diff --git a/CPP17.md b/CPP17.md index 7f3b0bd..340010f 100644 --- a/CPP17.md +++ b/CPP17.md @@ -178,6 +178,18 @@ const auto [ x, y ] = origin(); x; // == 0 y; // == 0 ``` +```c++ +std::unordered_map mapping { + {"a", 1}, + {"b", 2}, + {"c", 3}, +}; + +// Destructure by reference. +for (const auto& [key, value] : mapping) { + // Do something with key and value +} +``` ### Selection statements with initializer New versions of the `if` and `switch` statements which simplify common code patterns and help users keep scopes tight. diff --git a/README.md b/README.md index a75470f..dd96f20 100644 --- a/README.md +++ b/README.md @@ -429,6 +429,18 @@ const auto [ x, y ] = origin(); x; // == 0 y; // == 0 ``` +```c++ +std::unordered_map mapping { + {"a", 1}, + {"b", 2}, + {"c", 3}, +}; + +// Destructure by reference. +for (const auto& [key, value] : mapping) { + // Do something with key and value +} +``` ### Selection statements with initializer New versions of the `if` and `switch` statements which simplify common code patterns and help users keep scopes tight.