C++ Annotated: November 2019 – February 2020
Hi,
We’re happy to present our new edition of C++ Annotated, which includes our findings on C++ conferences, language evolution, various tools releases, learning materials, and community announcements. We hope you find this a useful and interesting read.
Today:
- C++ conferences.
- C++20 Is Done! Prague trip report by Phil Nash.
- Interviews, tools & techniques, language learning pieces, and thoughts.
- Releases.
C++ conferences
Because of the outbreak of COVID-19 and various national and local regulations and limitations for travel and mass events, many conferences have been cancelled, postponed, or moved online. So if you are planning a trip for an event, the best practices include checking regularly for news from your conference (organizers are now updating regularly), paying attention to national regulations if the event involves international travel for you, and reading and following CDC and WHO recommendations.
Catch these upcoming conferences while you can
You can find an up-to-date list of conferences around the world at the official C++ Foundation site. If you are excited to propose an interesting topic or talk, check out the ones with open calls for papers:
- NDC TechTown – closes April 23.
- CppCon and Meeting C++ CFP are not yet open.
Learn from these events even if you missed them
In our last edition of C++ Annotated, we listed conferences that were upcoming in November 2019. Given the current circumstances, it’s great to see that they all happened! The full list of past conferences, along with links to their YouTube playlists, can be found at the C++ Foundation site. A few worth mentioning from the Nov-Feb time period include:
- ACCU Autumn – A first-time Autumn edition happened in Belfast, and it was aligned with the C++ Committee meeting happening at the same place. Thanks to that, the event got several prominent speakers from the Committee, and in general there was a whole set of high-quality talks. Find the playlist on YouTube.
- Meeting C++ – The recordings of the regular and lightning talks are now available. While there were many really valuable presentations, we’d like to highlight just a few of our personal favorites:
- C++20: The small things by Timur Doumler. When it comes to a new standard, the community often focuses on the big changes. But C++20 is bringing lots of small goodies, and Timur nicely brings them to our attention. A nice result is that, while it might be hard to start using a big feature in your legacy project (due to its revolutionary aspect), the smaller ones are easier to adopt. That’s why we recommend watching this talk!
- Can AI replace programmers? by Frances Buontempo. Frances wrote the book on Machine Learning – literally. In this talk, she discusses both the philosophical and technical sides of the issues of today and of the future. Does Betteridge’s Law of Headlines apply to the title? The only way to find out is to watch the talk.
- code::dive has also published the recordings from the 2019 event.
- The playlist from the CoreHard Autumn 2019 event is available on YouTube.
C++20 Is Done! Prague trip report by Phil Nash
Instead of a regular “Proposals you don’t want to miss” section, this time we’ll discuss the recent C++ Committee meeting in Prague and its outcome. Phil Nash was there, and he’s ready to share a few highlights.
The important focus of the Prague meeting was finalizing C++20. At this stage, that mostly meant processing the last NB (National Body) comments so the draft could be sent off for ISO processing, after which it becomes an official C++ standard! There were a few additional bug reports, some of which surfaced during the meeting, but we (the committee) got through them all (or at least there was nothing left outstanding that could hold up the release)!
The bulk of that work was in the wording groups (Core and Library). The evolution groups were only tied up with C++20 about 20% of the time. Many of the study groups, including the two incubators, also met. So a substantial part of the week was actually devoted to C++23 and beyond!
C++20
From an end-user perspective, the tweaks to the C++20 draft were fairly minor – mostly just fixing issues that make the standard more consistent and, hopefully, adding less accidental complexity. A few small features were taken out as issues were identified that we didn’t have time or confidence to fix in a single meeting. In some cases, we actually fixed things. For example, aggregate initialization of std::array
s in the presence of CTAD introduced a few regressions which have now been fixed.
C++23++
Most of the more interesting, larger proposals come with caveats that they may not make it into C++23, or even C++26 in some cases! There are two, in particular, that most of us are hoping will make it into C++23 (but it’s most important that these are done right, even if that means waiting longer):
Pattern Matching
If you’re not familiar with pattern matching from other languages, in a nutshell you can think of it as extending switch statements to work with complex runtime, or even dynamic, values – that’s the matching part – but it also extends structured bindings with even more powerful destructuring capabilities. This combination makes pattern matching one of the most versatile and expressive features that is missing from the language today.
Even if you are familiar with the feature in general, this is definitely one of those features that is necessarily far more complex in C++ than in most other languages because of its rich variety of value categories. The challenge of this proposal is to leak as little of that complexity as possible without restricting how the feature can interact with the full language.
The syntax is still very much in flux, but here’s an example from r2 of the proposal, which matches on a std::variant
:
inspect (v) { <int> i: strm << "got int: " << i; <float> f: strm << "got float: " << f; }
In this meeting, we spent most of the time discussing whether match expressions should be required to be exhaustive, and whether there should be a difference between the statement and expression forms.
Reflection
Reflection is an umbrella term for introspection and generation. Many languages have runtime reflection, which can be very powerful but comes at the cost of performance (and executable image size). The proposals for C++ are for compile-time reflection (which can support runtime introspection, too). This promises to be one of the biggest additions to C++ since its very beginning!
In recent meetings, the discussion had been focused on migrating type-based syntax from the earlier proposals to take advantage of the advances in constexpr to make everything look much more like normal code. For example, holding lists of members in a constexpr std::vector
.
In the previous meeting in Belfast, and continuing in Prague, a change of direction was considered! The Circle project (a C++ compiler extended with simple, yet rich, metaprogramming facilities) has been in the spotlight, and the discussion has been about whether Circle’s approach is better (at least for generation) and whether we can take any cues from it.
The sentiment from the Prague discussion seemed to be that there are some thorny issues with Circle’s approach when it comes to cross-platform or embedded development, and this is probably not the direction we will take in the committee. However it was also recognized that, in some ways, Circle offers a drastically simpler usage – and maybe we could investigate more in that direction from where we are.
C++20 Is Done!
The “Official” C++20 photo
For more details, see Bryce Adelstein Lelbach’s exhaustive, as always, report on Reddit. See also the video that he did with Conner Hoekstra.
Interviews, tools & techniques, language learning pieces, and thoughts
In-class member initialization
In a recent blog post, Bartlomiej Filipek discussed how in-class member initialization has changed from C++11 to C++20. This basic overview is still worth reading as a refresher on all the changes that have been made through the standards. Bartek gives an overview of non-static data member initialization, bringing samples with side effects to the table. He also discusses copy and move constructors, highlighting how it works with aggregates (including some bug-fixes between C++11 and C++14) and bit fields. He adds a few words about inline variables, which allow for easier development of header-only libraries, as there’s no need to create cpp files for static variables or use hacks to keep them in a header file.
Finally, his blog includes more educational articles like that, so we recommend you follow and read it through from time to time.
C++20 Reference card
This one also comes from Bartek, who put together all the core elements of the newest standard and built them into a reference card. He did a similar thing for C++17, so if you sign in and subscribe to the mailing list, you’ll get both. C++20 is packed with some very notable features for you to remember, including concepts, modules, coroutines, ranges, the spaceship operator, constexpr/consteval/constinit, designated Initializers, std::format, std::span, a Chrono update, and much more. The card won’t teach you about these features in detail, but it will give you a general overview of the most notable and useful changes.
On Requires
expressions
In his blog, Andrzej Krzemienski has posted about a C++20 Concepts feature called requires
-expression. He actually departs from the Concepts feature and evaluates requires
-expressions on their own. One interesting usage he mentions is testing whether a class has a full interface implemented. This works because when a requires
-expression is used outside of any template, a compilation error is generated when the requirement is not satisfied. The blog post shows how you can use requires
-expressions to evaluate arbitrary predicates on types or to test whether any member functions exist, the constraints on their return type, and whether the function declared not to throw exceptions. At the end of his post, Andrzej discusses some interesting peculiarities about testing the validity of expressions in contrast to predicates.
Sourcetrail is free and open-source
In November, Eberhard Gräther announced that Sourcetrail is now free and open-source. Started as a Coati project, Sourcetrail is a source-code explorer for code written in C, C++, Java, and Python, which brings users an interactive combination of graph visualization and code display. Eberhard has presented both the approach in general and this particular tool to the public at several conferences, and it has definitely earned some love from the community. The source code is now available on GitHub, and you can support its authors via Patreon.
Drop-Dead-Simple
The author of the well-known CMake Tools Extension for Visual Studio Code has presented DDS – the Drop-Dead-Simple build and library management tool with a special focus on C and C++ libraries. It’s based on libman project concepts (a new level of indirection between package management and build systems), and it insists on a Toolchain as a major requirement (being itself completely independent of platforms and compilers). The main goal is to help people maintain and spread libraries easily. A detailed description of the reasoning behind this tool, the approach taken to building it, and some practical samples can be found in the blog post.
What is Modern CMake?
In his blog post, Kuba Sejdak states that linking with libraries in Modern CMake behaves very much like inheritance. The reason for this is that the linked target is passing all its PUBLIC and INTERFACE properties to the library it links with. The author provides two useful examples – hiding “private” headers from libraries in the linkage process and defining header-only libraries. Check them out to see how the new CMake “inheritance” can be used.
Move, simply, at Sutter’s Mill
Herb Sutter wrote a useful FAQ on Move, one of the trickiest and most widely misunderstood language features. The questions are interesting in their own right, but the answers are super useful, too. Herb discusses the state of an object after it has moved, whether it’s always changed or whether it can be documented, whether objects are somehow usable after being moved from, and much more. This is definitely a must-read for sorting out all the specifics of Move and for learning a few tricks.
Releases
- Visual Studio Online – Microsoft has unveiled the Visual Studio Online Public Preview. It brings Visual Studio Code, Visual Studio IDE, or the included browser-based editor to you for collaborative development, and it’s useful for prototyping features and reviews and for educational purposes. The environments work as the foundation and are Azure-hosted. Stay up to date with updates from the team about the recent changes.
- Qt Visual Studio Tools – They are coming to Linux with Visual Studio’s Linux projects support later this summer. The plan is to support Qt targets in the VS Linux development workload. A proof-of-concept sample shows a Qt project debugged both locally on Windows and remotely via gdbserver on Linux.
- CLion 2019.3 – The JetBrains IDE gets completion implemented on top of Clang, the long-awaited Ninja and other CMake generators, WSL2, built-in code coverage, and C++20 Concepts support. The CLion 2020.1 EAP is now available introducing CUDA support,
clang-cl
on Windows, and the IAR compiler for embedded development. - ReSharper 2019.3 – ReSharper comes with wider C++20 support (such as C++20 Concepts support, like in CLion), new type hints, and the sorting
#includes
formatter option. For game developers, it includes more profound Unreal Engine support. The 2020.1 EAP is also up and running with even more for C++20 and UE4.
The JetBrains C++ team
The Drive to Develop