Merge pull request #700 from tkruse/fix-examples

fix code examples
This commit is contained in:
Andrew Pardoe 2016-09-12 11:08:13 -07:00 committed by GitHub
commit 97503abeaa

View File

@ -3436,25 +3436,21 @@ Pointers and references to locals shouldn't outlive their scope. Lambdas that ca
##### Example, bad
{
int local = 42;
int local = 42;
// Want a reference to local.
// Note, that after program exits this scope,
// local no longer exists, therefore
// process() call will have undefined behavior!
thread_pool.queue_work([&]{ process(local); });
}
// Want a reference to local.
// Note, that after program exits this scope,
// local no longer exists, therefore
// process() call will have undefined behavior!
thread_pool.queue_work([&]{ process(local); });
##### Example, good
{
int local = 42;
// Want a copy of local.
// Since a copy of local is made, it will be
// available at all times for the call.
thread_pool.queue_work([=]{ process(local); });
}
int local = 42;
// Want a copy of local.
// Since a copy of local is made, it will be
// available at all times for the call.
thread_pool.queue_work([=]{ process(local); });
##### Enforcement
@ -18865,11 +18861,11 @@ It is common to need an initial set of elements.
template<typename T> class Vector {
public:
vector<std::initializer_list<T>>;
Vector(std::initializer_list<T>);
// ...
};
Vector<string> vs = { "Nygaard", "Ritchie" };
Vector<string> vs { "Nygaard", "Ritchie" };
##### Enforcement