Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2005-01-05 20:21:51


"CHAOS" <0xchaos_at_[hidden]> wrote in message
news:afccc62905010501325046bba6_at_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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk