|
Boost : |
From: Jason Hise (chaos_at_[hidden])
Date: 2005-07-18 10:19:22
Peter Simons wrote:
>Jason Hise writes:
>
> > I am adding a policy to control exactly what happens if
> > creation is attempted while the singleton instance
> > exists. The options thus far include throwing an
> > exception, doing nothing, or destroying and recreating
> > the singleton, depending on the policy used.
>
>Could you post some source code that illustrates what you
>mean by "creating" an instance?
>
>
singleton_ptr < Type > ptr; // smart pointer to single instance
ptr.create ( /*ctor params here*/ ); // creates the instance
ptr.create ( /*ctor params here*/ ); // instance already exists, what
should happen?
ptr->SomeMemberFunctionOfType ( 42 ); // perform an action on the singleton
>The usual approach to initializing static instances is
>call_once() from Boost.Thread; so I am curious to know how
>your approach compares to that.
>
>
I will have to look up call_once before I will be able to compare it
with my approach.
> > Does it make sense to have a similar policy for what
> > happens when attempting to destroy an already destroyed
> > instance?
>
>A failed assertion would be my preferred way to handle this
>condition; I don't see the need for a policy class.
>
>
Others have expressed (perhaps not publicly) that their preferred method
would be that secondary destructions are simply no-ops, rather than
being errors or asserting at all. Such conflicting interests make it
seem like a policy is indeed necessary. Or perhaps just multiple
destroy functions (destroy_if_exists, destroy_assert_if_null).
-Jason
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk