Boost logo

Boost Users :

From: sixfurdk (sixfur_at_[hidden])
Date: 2002-02-08 13:38:33


--- In Boost-Users_at_y..., Jon Kalb <kalb_at_L...> wrote:
> Can you compare/contrast your library to SingletonHolder<> in the
Loki
> library as described by Andrei Alexandrescue in "Modern C++ Design?"

I've briefly compared the Loki SingletonHolder<> with Singleton<>,
and have a few conclusions.

>From the suggested feature list, these are not supported by Loki (by
quick examination):

1) Supports the same interface/concepts as auto_ptr<>
3) Possible to use different Singletons of same type using names
(simultaneously)
5) Possible to Release By Reference (Optional, Not Default)

1) is useful for defining LinkPolicies. Consider the following:

template <class Object, class LinkPolicy> ObjectAdapter {
private:
    LinkPolicy<Object> object;
public:
    ObjectAdapter(Object object_) : object(object_) {;}

    void someFunction() {object->someOtherFunction();}
}

Having the singleton supporting the same concepts as auto_ptr, means
I can use it as a link Policy, hence telling the class compile-time
if it should aggregate with the object, associate with the object or
use Singleton<> to reference the object:

ObjectAdapter<SomeObject, auto_ptr> oa; // Aggregation
ObjectAdapter<SomeObject, Singleton> oa;

3) Allows for having several singleton objects or the exact same type
but with different internal states. This would allow me to do have
several identical, but unique resources, as in the following example:

Singleton<HP4000> lpt1("lpt1:");
Singleton<HP4000> lpt2("lpt2:");

5) I'm not quite sure if this is supported by SingletonHolder<>. But
this obviously reduces the timelife of resource allocations.

----
On the other hand the SingletonHolder<> supports features I have yet 
to study.
> I would guess that Andrei's singleton is probably the most familiar 
to
> people on this list and I suspect that if he survives the slings 
and arrows
> of submitting his smart pointer he will offer this as well.
Not, to mention that the SingletonHolder<> is older and has been 
tested by many people...
I'll work with the SingletonHolder to gain more experience with it.
Peter Sixhøj

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net