Add More Examples to Some Sections (#63)

* Add example to Structured Bindings
This commit is contained in:
Matthew Guidry
2019-10-14 10:41:00 -05:00
committed by Anthony Calandra
parent af7125a698
commit cdcd516ae8
2 changed files with 24 additions and 0 deletions

View File

@@ -178,6 +178,18 @@ const auto [ x, y ] = origin();
x; // == 0
y; // == 0
```
```c++
std::unordered_map<std::string, int> 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.

View File

@@ -429,6 +429,18 @@ const auto [ x, y ] = origin();
x; // == 0
y; // == 0
```
```c++
std::unordered_map<std::string, int> 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.