开发者

std::once_flag equivalent of BOOST_ONCE_INIT

开发者 https://www.devze.com 2023-01-25 05:30 出处:网络
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 d

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消