Boost logo

Boost :

Subject: Re: [boost] Is there interest in an alternative to the Singleton anti-pattern?
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2011-06-24 04:22:09


2011/6/24 Ben Robinson <icaretaker_at_[hidden]>:
> I look forward to your feedback on the Singularity Pattern. The unittests
> in Vault/Singularity/singularity_unittest.cpp are great to study first to
> see how Singularity is meant to be used.

I have some remarks:

1) class single_threaded - if you remove user defined destructor and
constructor, it will become a POD type and compillers will do better
optimizations

2) singularity_state, singularity_instance and singularity classes can
be combined together if you remove
BOOST_PP_REPEAT(BOOST_SINGULARITY_ARGS_MAX,
BOOST_PP_DEF_CLASS_TYPE_DEFAULT, _) from singularity and put this
templates directly for create functions. If you do so, code like:

singularity<Horizon, single_threaded, int, Event*, Event&>::create(3,
&event, event);

will look much better, just like:

singularity<Horizon, single_threaded>::create(3, &event, event);

Then, FRIEND_CLASS_SINGULARITY macro will be much shorter

4) May be, it would be much better to derive from singularity. Then
the code will look just like this:
Horizon::create(3, &event, event);
or like:
Horizon< single_threaded >::create(3, &event, event);

5) It would be great, to have a get() function in singularity, that
returns reference

It's just what I saw in a 15 minutes of review. I will make a more
deep look a little bit later. Any comments are welcomed.

Best regards.
Antony Polukhin


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