Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-01-09 22:48:54


Scott Woods wrote:

> <>...one day you are asked to produce a self-verifying version
> of your switch that runs two instances side-by-side. Or you are
> asked to do some call-setup performance testing, i.e. you need
> to run two instances of your PBX against each other. Or you
> need to perform soak testing that needs 6 instances in a single
> executable. And so on. Should the abstraction known as Singleton
> truly preclude there ever being more than 1 instance?

This is an interesting point. Perhaps the derived template class could
be templated itself to take one parameter, an int. Then a new instance
of the singleton could be referenced at any time by simply referring to
the singleton type with a different unique ID for the template
parameter. The field could default to zero for normal usage as a
singleton. Ex:

template < int I = 0 >
class Important : Singleton < Important >
{
protected:
    Important ( ) { }
    ~ Important ( ) { }

public:
    // important stuff here
};

void TestWithThreeInstances ( )
{
    Important < 0 > :: Pointer instZero = Important < 0 > :: GetInst ( );
    Important < 1 > :: Pointer instOne = Important < 1 > :: GetInst ( );
    Important < 2 > :: Pointer instTwo = Important < 2 > :: GetInst ( );
    // do testing here
}

-Jason


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