C++17 is rolling along at a fast pace. As of June 30, the proposed set of features for the language revision is complete. That was also the day the C++17 committee held its final features meeting in Oulu, Finland, the result of which includes changes that will be available as add-ons for compilers.
One of the biggest additions to the language is std:variant. This acts like a union, but it can tell you what it currently contains. It’s basically a type-safe union implementation, and in the future it will likely be used to build advanced capabilities, like pattern matching.
For developers working with templates, the new constexpr if function will allow them to write code that instantiated depending on a compile-time condition. This would allow code to be written, (for example, that can handle integers) to be coupled with code that can handle floating-point math. During compilation, either can be favored and the other not compiled, according to the needs of the numbers present at compile time.
In C++14, Lambdas were given the ability to have generic parameters with the addition of auto. Auto has now been expanded to support template parameters. This will make it easier to write templates, as auto takes less code to complete.
New to C++17 is the addition of structured bindings. Previously, this type of behavior could be accessed via a workaround using std::tie to assign a tuple or pair to different variables directly. Previously, those variables had to be instantiated already, but now they can be initialized in one line. It is also now possible to declare variables within an if statement.
Jens Weller is a C++ evangelist and developer based in Germany, and he wrote about the new standard in a blog post about C++17. “C++17 evolves the standard further, the tools for standardization have matured and are working,” he wrote. “Probably the biggest gain for C++. Those who would like to add certain features to the next C++ Standard (a.k.a. C++NEXT/C++20), should now start to make their plans.”
There is still more work coming around C++17, most specifically around features that were put off and are destined to be implemented as compiler add-ons. These add-on features are currently implemented in individual compilers, but not across platforms. Visual Studio, for example, offers modules already, while GCC is the first compiler with concept support.