mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
F.21 updated C++17 example
This commit is contained in:
parent
7c9ec43f8b
commit
6187049d95
|
@ -2570,8 +2570,7 @@ With C++11 we can write this, putting the results directly in existing local var
|
||||||
|
|
||||||
With C++17 we may be able to write something like this, also declaring the variables:
|
With C++17 we may be able to write something like this, also declaring the variables:
|
||||||
|
|
||||||
auto { iter, success } = myset.insert("Hello");
|
if (auto [ iter, success ] = myset.insert("Hello"); success) do_something_with(iter);
|
||||||
if (success) do_something_with(iter);
|
|
||||||
|
|
||||||
**Exception**: For types like `string` and `vector` that carry additional capacity, it can sometimes be useful to treat it as in/out instead by using the "caller-allocated out" pattern,
|
**Exception**: For types like `string` and `vector` that carry additional capacity, it can sometimes be useful to treat it as in/out instead by using the "caller-allocated out" pattern,
|
||||||
which is to pass an output-only object by reference to non-`const` so that when the callee writes to it the object can reuse any capacity or other resources that it already contains.
|
which is to pass an output-only object by reference to non-`const` so that when the callee writes to it the object can reuse any capacity or other resources that it already contains.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user