BT

InfoQ Homepage News C++17 Feature List is Now Complete, Enters Review

C++17 Feature List is Now Complete, Enters Review

Bookmarks

During the last meeting in Oulu, Finland, the ISO C++ committee completed the definition of the C++17 feature list. At the meeting, a number of new language and library features were approved, including constexpr if, template <auto>, structured bindings, and others.

As committee member Jens Weller writes, now that the feature list has been closed, a review period will start:

The next two meetings mostly will process reviews, feedback and issues flagged by national bodies. This will not add new things to the standard, but can have minor or major changes.

Among the features that were added to C++17 in the last committee meeting in Oulu, Weller highlights the following:

  • std::variant, which provides a safe, generic, stack-based discriminated union container.

  • if constexpr(expression), which can be regarded as C++ version of a compile-time if.

  • Template auto, which allows to declare non-type template arguments with auto. This will allow to write:

      template <auto value> void f() { }
      f<10>();        // deduces int
    

    Herb Sutter stresses the various possibilities opened up by this feature, such as writing a function template that includes all the special cases of its algorithm right within its body and not through a set of template specializations.

  • Structured bindings, which makes it possible to declare and initialize multiple variables from a tuple:

    tuple<T1,T2,T3> get_tuple();
    auto [a , b , c] = get_tuple();
    
  • variable declarations in if and switch, similarly to what the for loop already allowed:

    map<int,string> mymap;
    if (auto result = mymap.insert(value); result.second) {
    // insert succeeded, and result is valid for this block
    use(result.first);  // ok
    // ...
    }
    

Additionally, Sutter mentions new features that deserve to be highlighted, including:

The list above only includes new features that have been approved in the last committee meeting, but the list of features that will be part of the new C++17 standard is much longer. A useful resource to get an overview of what the new standard should include at the end of the review process can be found in this Stack Overflow thread.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.