mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 01:54:36 +03:00
Add More Examples to Some Sections (#63)
* Add example to Structured Bindings
This commit is contained in:
committed by
Anthony Calandra
parent
af7125a698
commit
cdcd516ae8
12
CPP17.md
12
CPP17.md
@@ -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.
|
||||
|
||||
12
README.md
12
README.md
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user