mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Update CppCoreGuidelines.md
This commit is contained in:
parent
17fe8a957f
commit
7a5ab334a0
|
@ -13393,17 +13393,10 @@ Application concepts are easier to reason about.
|
|||
|
||||
##### Example
|
||||
|
||||
void publish(std::string* msg)
|
||||
{
|
||||
// ...
|
||||
*msg = "Hello";
|
||||
// ...
|
||||
}
|
||||
|
||||
void some_fun() {
|
||||
std::string msg;
|
||||
std::thread publisher(publish, &msg); // bad (less expressive and more error-prone)
|
||||
auto pubtask = std::async(publish, &msg); // OK
|
||||
std::string msg, msg2;
|
||||
std::thread publisher([&] { msg = "Hello"; }); // bad (less expressive and more error-prone)
|
||||
auto pubtask = std::async([&] { msg2 = "Hello"; }); // OK
|
||||
// ...
|
||||
publisher.join();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user