开发者

std::once_flag equivalent of BOOST_ONCE_INIT

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜