Which Singleton library in BOOST do you choose?
Google results say there ar开发者_如何学Ce more than 1 singleton template/baseclass in boost, which one do you suggest?
You shouldn't use the singletons in boost, they are for internal purpose only (see the "detail" folders of separate libes). That's why you don't have a Singleton library (yet) exposed on the boost website.
A singleton class is very simple to implement but there are many variants that are useful in specific cases so you should use something that fit what you think a singleton should behave like.
Now, there is other libraries providing singleton, the most generic being Loki. But it could blow your mind ;)
Update : There is now a proposed library called Singularity that is meant to provide non-global singleton (with option to make it global) that forces you to have clear creation and destruction points of the object.
See the review request : http://boost.2283326.n4.nabble.com/Review-Request-Singularity-tt3759486.html
Some boost devs seems to consider using it instead of some hacks, but C++11 makes makeing a class Singleton easier than before so it will depends on the review.
My version of boost has following singleton.hpp headers:
C:\boost_1_38_0\boost\pool\detail\singleton.hpp
C:\boost_1_38_0\boost\serialization\singleton.hpp
C:\boost_1_38_0\boost\thread\detail\singleton.hpp
I haven't used any of those, but I'd probably stay away from the ones in detail directories.
Anyway, http://torjo.com/tobias/index.html#boost_utility_singleton.reference.singleton looks like one to use, but it doesn't seem to be really a part of boost (not accepted yet?).
精彩评论