Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2005-07-27 18:34:34


Jason Hise wrote:
> Fernando Cacciola wrote:
>
>> Jason Hise wrote:
>>
>>
>>> 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).
>>>
>>> [...]
>>>
>>>
>>
>> Use Boost.Optional:
>>
>> http://www.boost.org/libs/optional/doc/optional.html
>>
>>
> I don't see how this helps... optional does not appear to allow member
> functions to be called when the object does not exist. Instead, it
> simply asserts that the object does exist before the -> operator
> returns. For my hypothetical zombie_ptr, I want to make usage when
> the instance does not exist a no-op, not an error.
>

if ( ptr != null )
     return optional<result_type>(ptr->member_function(...));
else return optional<result_type>();

Fernando Cacciola
SciSoft


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