I'm watching Herb Sutter's CppCon 2014 talk about lock-free programming.
On handout page 7, we have the following code:
static unique_ptr<widget> widget::instance;
static std::once_flag widget::create;
widget& widget::get_instance() {
std::call_once( create, [=]{ instance = make_unique<widget>(); } );
return instance;
}
My question: Why is a [=] capture used here, rather than say [&] (or [&instance])? cppreference says:
[=]captures all automatic variables used in the body of the lambda by copy and current object by reference if exists
but we don't have any automatic variables nor do we need the current object.
Aucun commentaire:
Enregistrer un commentaire