Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-07-26 12:10:17


I am trying to come up with a mechanism which allows member functions of
the singleton to be called if the instance exists, and which do nothing
if the instance does not exist (no creation is attempted, the operation
is simply skipped). My current idea is a member function of the
singleton pointer named zombie_call, which would be used something like:

ptr.zombie_call ( &MySingletonType::SomeFunc, param1, param2, ... );

The only problem I have is what to do if the instance does not exist and
the member function has a return value. Should I just return a
default-constructed object in these cases? (And what should happen if
the return type does not have a constructor taking no arguments?)
Should I append a parameter to the end of zombie_call which is returned
if the instance does not exist, and have it default to a
default-constructed object? Should I append a parameter that is a
reference to the return type, and just assign the return value to it if
the operation is successful? (And what happens if the return type is
already a reference?) Should I just enforce that member functions
called with zombie_call return void?

Also, is there any way to make the syntax of the call a bit nicer? I
was originally hoping to have a separate pointer type called zombie_ptr,
which just behaved in this manner when functions were accessed via
operator->, but I couldn't think of a non-intrusive way to pull it off...

Any and all thoughts are appreciated.

-Jason


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