C++ Annotated: Apr – Aug 2017
Today we are happy to share our next compilation of C++ news with you.
C++ Annotated: April – August 2017
A long time has passed since the last edition of C++ Annotated. Which means today we have lots of great articles and news to share with you. In this edition:
- C++ language news
- Recent events like ACCU and C++Now
- Upcoming events
C++ language news
With C++17 ready for final publication by the end of 2017, we can now start thinking about the future of C++ and in particular C++20. The Toronto C++ committee meeting was solely about just this! Just look:
- Concept TS was merged into C++20 draft. It takes now only one clean syntax (out of three) and doesn’t include function concepts.
- Coroutines TS, Networking TS and Ranges TS are done, Modules TS is quite close.
- Several nice enhancements like designated Initializers, template syntax for generic lambdas, default member initializers for bit-fields and others.
It seems that Fall will bring even more exciting features to C++20, and maybe for example, compile-time reflection. (And here’s one to definitely have a check of the talk by Jackie Kay from C++Now). And not to mention the library evolution group and new standard library under discussion. To find out more check Herb Sutter’s traditional trip report. And if you want a summary table view, check the trip report by Botond Ballo.
The trickiest thing about ACCU 2017 was keeping secret Herb Sutter’s keynotes on metaclasses. This was the closing talk of the conference, but it made the whole audience of the big room at the Marriott hotel stay until very late. Now, that the proposal is live and the ACCU’s talk is finally published, everyone can learn more about this exciting topic.
What can make the C++ language more powerful and simpler? Can we avoid boilerplate code? Can we talk to a C++ compiler in C++? Can we get DSLs out of C++ without vendor-specific compilers? The answer to all these questions is ‘Yes’ if we use metaclasses.
More specifically, the idea is to enable you to describe some abstractions to the compiler and get metaclasses definitions that can be later used in the code. Today struct and class are the two main ways to define a type in C++, but with metaclasses, we can access way more!
One typical example is interface, which is:
- an abstract base class, and
- all public virtual functions, and
- no copy/move or data members.
Check the live sample in Compiler Explorer.
Or another one, value:
- default construction, destruction, copy/move, and comparison (memberwise by default),
- and no virtual functions or protected members.
Check the live sample in Compiler Explorer.
Or any of the others you create! A standard library for such metaclasses has to be created, as well as a way to include the definitions into the regular C++ code.
The full collection of links for further reading can be found in this blog post by Herb Sutter. And if you are looking for a short technical summary of Herb’s proposal, check the blog post by Jonathan Boccara.
This year’s ACCU conference was huge and not only because of the Herb Sutter’s keynotes (though now it could be a tricky task to organize something more exciting). A couple of talks worth mentioning are: Odin Holmes’ “Modern C++ Design reloaded” (again about moving in the direction of meta-programming), “Mongrel Monads, Dirty, Dirty, Dirty” by Niall Douglas (showing how errors in C++ could be handled and providing a nice comparison of the options in terms of performance), “Grill the C++ committee” session (from a C++17/20 discussion to advice on starting a C++ proposal), and many others.
The playlists with all the videos are available and organized by the days on ACCU’s YouTube account. There are also a couple of trip reports worth reading, including one from JetBrains, where we share our booth experience and general impressions and thoughts on the conference.
If you were ever interested in cutting-edge C++ and wanted to work on new language features with a group of people with a similar deep interest in the language itself, C++Now is the proper place. A week spent in Aspen, Co, USA will fill you with dozens of bright and outstanding ideas, that will become your everyday C++ routine tomorrow.
This year’s event was no exception. While the unique feature of C++Now is a drive for discussions and collaboration that leads to hours of hot debate on-site, you can still get lots of useful information from the recordings. The playlist is already available.
And if you need recommendations on how to start over, I’d suggest you look at Tony Van Eerd’s “Postmodern C++” (awarded “Most Inspiring” and “Most Engaging”), Ben Deane & Jason Turner “constexpr ALL the things!” (awarded “Best Presentation”), all three parts of Alisdair Meredith talk about std2 (1st, 2nd, 3rd) discussing the future of the standard library in the world of modules-based approach and concept usages, and a very practical talk about Modern CMake by Daniel Pfeifer.
The JetBrains trip report can be found here.
The upcoming months are going to be pretty packed with lots of great C++ events. It will all start with CppCon 2017 in September followed by Meeting C++ 2017 later in November. These two events introduce Bjarne Stroustrup, Herb Sutter, Lars Knoll, Matt Godbolt, Sean Parent, and Kate Gregory as keynotes speakers, as well as dozens of other great speakers.
The Audio Developer Conference (former JUCE) will run in London in November, and will gather audio developers from all over the world to discuss the problems in the audio processing field, the specific libraries and solutions, as well as news around C++ language.
Past, Present and Future of C++
In May, Bjarne Stroustrup joined CppCast for the anniversary 100th episode of the podcast. He talked about his expectations for C++20 (in a nutshell, Concepts, Modules, Contracts, Networking, and likely no Reflection), as well as issues with compile times, code cleanliness and possible improvements, he also touched on the current state of the C++ committee and more.
Addressing a “time machine question” about what Bjarne would change in C++ if he could go back in time, he talked about good interfaces and the possibility of getting Concepts. Check the episode for more interesting thoughts from the C++ language creator.
Deep dive into C++ Core Guidelines
Rainer Grimm runs quite an interesting blog Moderness C++, and this month there is a series of detailed posts about C++ Core Guidelines in it. Rainer started with the question why do we need guidelines for C++ coding at all? The reasons he gives:
- The language is complicated for the novice.
- With each modern standard, the language changes the way we think and solve problems in C++.
- C++ is a language for safety critical systems, where the cost of error is high. But some existing guidelines are based on very old standards, and thus are outdated.
Saying this, Rainer hopes that C++ Core Guidelines will help to solve current issues. So he dedicates a series of posts to discussing the currently existing rules (350 in total) in detail, creating fables from each group and tieing them all together (posts are grouped in sections following the Guidelines structure). For example, learn about recommended practices to write Function Definitions, general rules for Classes, and many others.
The C++ language is tough and complicated and developers often ask about recommended books on C++ good practices. All these books are well-known, but it’s always convenient to have them all in one list. So here it is, prepared by Jonathan Boccara in his blog. One may find there lots of modern language classics like Scott Meyers series, Herb Sutter’s (More) Exceptional C++, and Modern C++ Design from Andrei Alexandrescu, there are recommended books on Boost, template metaprogramming, and more.
C++ Online Compilers
Another list that might be useful for many C++ developers is published by Arne Mertz in his blog Simplify C++. That’s the list of online C++ compilers. This could serve several goals:
- Quickly check C++ code snippets without setting the whole toolchain on your machine.
- Compare several compilers or several versions of one compiler (especially for the case, when you develop using one version and build on a target platform using another one).
- Learn and experiment with the new language features.
You can also often share the code snippet online using such services.
Compiler Explorer (by Matt Godbolt) is one of the most famous online compilers. It’s often used during meetups and conference presentations, especially when talking about language features. It also shows the assembly produced by the compilers. But there are more names mentioned in the blog post, with their peculiarities highlighted.
Refactoring C++ code webinar
On August 17th we’ve run a live webinar with Arne Mertz as a speaker, the recording is now live. In an hour long talk, Arne covered general strategies and effective refactoring processes, showing lots of samples. It all started with one application where all the code was placed in one file. Step by step, Arne was extracting functions, removing duplicates, demonstrating parallel change strategy, extracting domain logic into a separate class and playing with the duplicate & reduce technique. There is a sample project available on GitHub, so you can follow the whole process.
Conan C/C++ package manager webinar
If you have ever developed a large C/C++ project or were interested in reusing certain packages and libraries, you might wonder about package and dependency managers for C/C++, then Conan is what you are looking for! In July we did a live webinar with SW Engineers from the JFrog team, who are actively contributing to Conan. An hour talk covered topics such as: creating packages from your own sources, discussing Conan profiles (what are they and how they help), and a way to skip the local cache to depend on a locally edited package. As usual, the demo project is available to try all the tips on your own. Find the recording by the link.
Compile-time string concatenation
Can you concatenate two strings in compile-time in C++? Can you do that with C++11? The blog post by Andrzej Krzemieński started with a typical static initialization order fiasco sample:
Quite a common solution might be “introduce a function notation to read a constant value”, but there are several reasons why this is not ideal and can lead to slow-downs. And here the author comes to compile-time constants and the need for compile-time concatenation. The rest of the article is about building a solution, that becomes more complicated because of C++11 and its restrictions.
A bug in GCC
If you think GCC guarantees you the exception safety, then you should check this story about the related bug in GCC. It shows a simple case that uses aggregate initialization and leads to a problem. Namely, you can get a Member that was initialized but never destroyed. The author later made another blog post showing another case where the same error occurs and that is close to real-world C++ code. Check these samples at least to confirm you don’t get similar leaks in your programs.
When comparison function does it wrong
PVS-Studio is famous for checking lots of projects for potential errors and sharing the result of such checks in their blog. In this post Andrey Karpov collected possible issues with comparison function, to share real-program examples. Several error patterns are discussed:
- Issues that come out of repetitive checks and code duplication
- Incorrect Check of Null References
- Typical issues within loops conditions
- And much more
Check real errors from Unreal Engine 4 code, Chromium, Qt, CryEngine V, MongoDB, LibreOffice and many others.
The StarCraft II API
Blizzard welcomes everyone interested, to try and implement a bot using the StarCraft II API. The library appeared on GitHub, along with a couple of tutorials (on how to create various types of bots, run simulator, etc.) and a list of examples. The API is built around protobuf defined protocol, it uses CMake to generate project files and Doxygen to generate documentation. The library supports all three platforms (Linux, Mac, Windows).
The latest release of CLion (2017.2) brought integration with Clang-Tidy, which means first and foremost that users are able to see Clang-Tidy warnings and benefit from Clang-Tidy quick-fixes right inside the IDE, in just the same way it works for CLion’s own built-in inspections. And secondly it means users can add their own check to Clang-Tidy and get them instantly in the IDE.
In addition to that, some existing inspections and quick-fixes were updated, C++17 came to the New Project Wizard, other improvements to PCH support and disassembly view in debugger were introduced. Learn more by the link.
Another C++ tool from JetBrains, ReSharper C++, which is a Visual Studio extension for C++, also got an update. With version 2017.2 ReSharper C++ now supports ClangFormat configuration files as a source of information for the built-in formatter. The tool shows the progress with C++17 features (selection statements with initializer, using in attribute namespaces, and capturing *this by value), polishes support for some C++11 features (including the work around friend declarations and user-defined literals). In addition, this release improves the code navigation and adds several new code inspections.
Qt Creator 4.4 is nearly ready for its final release. This version brings inline annotations for warnings and errors from the Clang code model (just like in Xcode) and changes to Rename refactoring that is now capable of doing Rename Files when renaming a symbol. And built-in Clang code model helps now with the highlighting of the identifier at the cursor. Check the blog post for other changes.
That’s it for now. Thanks for reading and stay tuned!
Subscribe to Blog updates
Thanks, we've got you!
ReSharper C++ 2023.2: Safe Delete Refactoring, AI Assistant, New C++23 and C++20 Features
New release brings the Safe Delete refactoring, support for several new C++20 and C++23 features, ReSharper’s AI Assistant, and more.
ReSharper C++ 2023.1: Call Tracking, Macro Expansion Preview, and Support for C++23 Features
ReSharper C++ 2023.1 brings updates for C++20 and C++23 features, and also introduces Call tracking for incoming calls and macro substitution previews in tooltips and Quick Documentation popups.
ReSharper C++ 2022.3: C++20 Modules and Clang-Format Integration
ReSharper C++ 2022.3 introduces experimental support for C++20 modules and provides seamless integration with clang-format.