Last week the ISO C++ standards working group met in Oulu, Finland, and I attended representing Embarcadero. The main point of the meeting was to finalize the C++17 committee draft, ie the basics of what will be in C++17. A lot of papers were presented adding new language or library features.
There is a great reddit thread that covers much of what was added. Here are a few items that stood out to me, along with a few observations:
- template auto: allowing non-type template arguments to be automatically deduced. The proposal doesn't go as far as some may have hoped (no "..." syntax, for example) but will be useful as-is. It's interesting to note how much "modern" C++ is making use of auto - I'm seeing fewer and fewer explicit types in many code samples.
- Template argument deduction, allowing syntax like "tuple foo<1, 2.5>;" without fully specifying the type for tuple.
- const_expr if, mainly intended for avoiding lots of template specialisation
- if with an initializer (the same way a for statement can have an initialization in it) - something like "if (int i = foo(); i == 2) {..."
- Structured bindings. This is (to me) a very neat change allowing initialisation of multiple variables based on a tuple or struct, something like: "auto [a, b, c] = foo();" where foo() returns a structure with three elements. There was a lot of discussion about how far to take this and future pattern matching improvements. I am a fan of languages that regard data types as flexible (tuples, for example, allow easy grouping of several items) and unwrapping to variables is an easy and clear concept.
- Variant<> is moved in from the experimental namespace
- Splicing between maps, and between sets (that is, moving elements between them by moving the nodes in the containers, not by moving the elements themselves.) This is map <-> map and set <-> set, not map <-> set.
- std::byte (see also this related paper) - there has never been a standard definition for byte. Now there is. To me, and this is a personal note, it is odd - it is explicitly not a number, for example (is or should a byte be regarded as a number, a collection of bits, or something else?) and includes few operations. The proposal is intended to describe a byte in storage rather than a generic all-rounder byte, but was named "byte" regardless.
- Ordered by default - proposed by Alisdair Meredith, a previous C++Builder PM. This addresses the situation where you can order a type, but the order it naturally follows is not less-than. The typical example is a complex number, but the example I've run into many times is any kind of point, such as a GPS position. One GPS position is not less than another, but you can define a sorting order, yet making it operator< seems wrong - but until this proposal was required for many containers, like std::map. This proposal allows specifying an ordering trait, which defaults to std::less but which can be replaced, allowing you to define an order for a one of these non-mathematical-ordered types without incorrectly (by understanding) defining operator<.
Concepts and modules are not included, but that was already known before this meeting. People seem hopeful that modules at least will go into C++19.
On a side note, Oulu is just a couple of hundred kilometers south of the Arctic Circle, and midsummer's day fell during the week we met. It never got dark.