Skip to content

Latest commit

 

History

History
99 lines (75 loc) · 1.75 KB

File metadata and controls

99 lines (75 loc) · 1.75 KB

Other useful features


Nested namespace definitions (C++17)

You can nest namespaces like this:

namespace A::B::C {
  ...
}

Instead of this:

namespace A {
  namespace B {
    namespace C {
      ...
    }
  }
}

Class template argument deduction (C++17)

From C++17 class template arguments can be deduced automatically. Automatic template argument deduction was available earlier only for template functions.

std::pair p(1, 'x'); // C++17: OK, C++14: error: missing
                     //template arguments before p
std::pair<int, std::string> p(1, 'x'); // C++14: OK
auto p = std::make_pair(1, 'x'); // C++17: OK, C++14: OK

Selection statements with initializer (C++17)

New versions of the if and switch statements for C++:

if (init; condition)

status_code foo() { // C++14
    { //variable c scope
        status_code c = bar();
        if (c != SUCCESS) {
            return c;
        }
    }
    // ...
}

switch (init; condition)

status_code foo() { // C++17
    if (status_code c = bar(); c != SUCCESS) {
        return c;
    }
    // ...
}

Selection statements with initializer (C++17)

{
    Foo gadget(args);
    switch (auto s = gadget.status()) { // C++14
        case OK: gadget.zip(); break;
        case Bad: throw BadFoo(s.message());
    }
}
switch (Foo gadget(args); auto s = gadget.status()) { // C++17
    case OK: gadget.zip(); break;
    case Bad: throw BadFoo(s.message());
}

Overview

Overview of modern C++ features