|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-07-16 08:43:31
"Calum Grant" <calum_at_[hidden]> writes:
>> > I've been following this dual_state vs optional discussion for a
>> > while. It seems to me that one should really have a policy
>> class that
>> > defines the default behaviour when the value is unassigned. This
>> > policy should define whether to
>> >
>> > - throw an exception
>> > - construct an object on the fly
>> > - return a default
>> > - return a null pointer
>> > - whether to return by value or by reference
>> >
>> > A second point, can't all this be achieved by adding
>> policies to smart
>> > pointers?
>>
>> Whoa; smart pointers and boost::optional are not very closely
>> related beasts.
>
> I mean, a weak_ptr and optional both have 0 or 1 pointees, so there is
> at least a passing resemblance.
Merely a syntactic one. optional is not a smart pointer; it just uses
* and -> to provide access to its contained object.
> In the absence of Boost, I would probably use a std::auto_ptr to
> store an optional field, which is, um, a smart pointer. I realize
> that Optional is implemented slightly differently.
I wouldn't characterize it as a "slight" difference.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk