From cdcd516ae826658c2104a611e7c0f58d31d6a9c3 Mon Sep 17 00:00:00 2001 From: Matthew Guidry Date: Mon, 14 Oct 2019 10:41:00 -0500 Subject: [PATCH] Add More Examples to Some Sections (#63) * Add example to Structured Bindings --- CPP17.md | 12 ++++++++++++ README.md | 12 ++++++++++++ 2 files changed, 24 insertions(+) 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.