Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-07-25 17:15:09


David A. Greene wrote:

>I got home and realized that I still have quite a bit of documenting
>to do. In order to make this more immediately useful to Jason and
>others, I'll get something into the vault this weekend.
>
That does sound useful, I look forward to playing with it. In the mean
time, what do people think of the following solution?

namespace boost
{
    namespace singleton
    {
        struct name
        {
            // typedef all default policies here
        };

        typedef name unnamed;
    }

    template
    <
        typename Type,
        typename Name = singleton::unnamed
>
    class singleton_ptr { /*...*/ };
}

The name acts as both the policy mechanism and as a unique identifier to
allow multiple singletons of the same type to exist. Client code can
define a name by deriving from singleton::name and typedefing any
policies needed, allowing the defaults for the others to be inherited
from the base class. Ex:

using namespace boost;

struct score : public singleton::name
{
    typedef singleton::dependency_lifetime lifetime_policy;
    // leave defaults for other policies
};

struct lives : public singleton::name
{
    typedef singleton::dependency_lifetime lifetime_policy;
    // leave defaults for other policies
};

typedef singleton_ptr < int, score > score_ptr;
typedef singleton_ptr < int, lives > lives_ptr;

-Jason


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