What's new in C++17

1 min read

Structured Bindings

auto [a, b, c] = tuple('a', 1, 0.5);
map<int, int> mymap = {{1, 2}, {3, 4}};

for (const auto& [key, value] : mymap) {
    // ...
}
for (auto [a, b] = tuple(0, 'a'); a < 5; a++) {
    // ...
}

Template Argument Deduction

auto p = pair(2, 4.5);
auto p = pair<int, double>(2, 4.5);

Selection Initialization

if (auto a = getval(); a < 10) {
    // ...
}
switch (auto ch = getnext(); ch) {
    // ...
}

  1. https://www.fluentcpp.com/2018/06/19/3-simple-c17-features-that-will-make-your-code-simpler/
  2. https://hackernoon.com/a-tour-of-c-17-if-constexpr-3ea62f62ff65
  3. https://stackoverflow.com/questions/38060436/what-are-the-new-features-in-c17