
"CHAOS" <0xchaos@gmail.com> wrote in message news:afccc62905010501325046bba6@mail.gmail.com...
This post refers to the following code: http://www.ezequal.com/chaos/libs/singleton.h
I have developed a templated singleton class which enforces almost every rule of the singleton pattern at compile time. This library provides a very clean, flexible format for client code to implement its own singleton classes which may have dependencies on each other. I have three questions.
We could definitely use a Singleton class in boost, I write enough of them, with enough boilerplate, that it would be very convenient to have a class I can derive from. However, I have several issues with your implementation: 1) I strongly dislike your virtual operator=(const SingletonBase &). Most of the Singletons I use don't have any virtual functions, and I would rather not add any if I don't have to. In your comments you say you only define it to make sure that SingletonBase cannot be instantiated. Keeping the destructor (or all the constructors) non-public has the same effect. 2) It would be easier on users if, instead of Singleton<T> inheriting from T, you reversed it so that T must inherit from Singleton<T> (the curiously recurring template pattern). This would make it possible to communicate in both directions between T and Singleton<T>. It would also make it much easier to turn an existing class into a Singleton. Joe Gottman