I'm working with some code I borrow开发者_Go百科ed from here which uses boost::call_once to make a singleton class, and would like to convert everything to use C++0x's std::call_once to remove the dependency on Boost. Does anyone know what the Std equivalent of BOOST_ONCE_INIT is?
std::once_flag
has a constexpr
constructor, so instances with static storage duration are always statically initialized.
Incidentally, the point about scoped_ptr
is important --- the constructor of the scoped_ptr
instance is NOT static initialization, so will race with any uses of the singleton before it has been initialized, and possibly overwrite the pointer.
精彩评论