Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-02-13 19:20:07


I recently discovered that my singleton could potentially be used in a
way other than as a base class. For example, to create and use a
singleton instance of a class which could have other ordinary instances
as well, one could just do:

class Example
{
public:
    void foo ( )
    {
    }
};

// elsewhere...

singleton < Example >::pointer ptr;
ptr->foo ( );

In addition, one could make a singleton who's instance refers to another
class by deriving from a singleton of that type, as follows (using the
Example above):

class ExampleSingleton : public singleton < Example >
{
private:
    ExampleSingleton ( );
    ~ ExampleSingleton ( );
};

which would essentially create a shorter name for singleton < Example >.

I need opinions: should this type of usage be allowed, or should I find
some way to make it fail to compile? If allowed, should it be
encouraged and/or documented?

-Jason


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