From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2002-12-11 09:31:17
----- Original Message -----
From: "Tanton Gibbs" <thgibbs_at_[hidden]>
To: "Boost mailing list" <boost_at_[hidden]>
Sent: Tuesday, December 10, 2002 10:10 PM
Subject: Re: [boost] Formal review: Optional library
> > > > That's why it hands you a pointer to the value, because you can test
> > > > pointer
> > > > for NULL; but that's it.
> > > > IOWs, the pointer returned by optional is conceptually a handle, not
> > > > pointer.
> > > > That's why I like the member function peek() much better than get().
> > >
> > > I still much prefer the standard get(), even if I bought into the rest
> > > the rationale. It's what people expect because of std::auto_ptr.
> > >
> > I see.
> > I counted 2(two) in favor of get(), and one (me :-) in favor of peek().
> > I'll be democratic on this one, though I hope I can get more counts.
> For what its worth, I vote in favor of value semantics. It seems much
> to me to remember to call initialized when I want to test validity than it
> to remember which of *, peek, get, get_value to use in which case. Also,
> the fact that I can assign a non pointer value to a smart-pointer is kinda
> To me, it just doesn't fit the smart pointer mold and the interface is
> because it is trying to shape an elephant into a rhino -- yeah, their
> shaping a hippo to a rhino might be easier. Therefore, I urge you to
> value semantics as I think those examples were much cleaner and clearer
> the examples I have been seeing.
value semantics were not just considered but used.
The original optional<> I implemented used value semantics,
but after a long time, I found it a lot more confusing that
with value semantics.
Pointers convey the notion of uninitialization quite naturally.
For instance, for an optional argument to a function
pointer are typically used.
void foo ( int* opt )
if ( opt )
this is the typical way you deal with an optional argument.
optional<> follows the same pattern for those cases were true
pointers cannot be used since it would require a dynamic
optional<int> opt = foo();
if ( opt ) // pretend safe-bool is added
There is an analogy between the way pointers are ordinarily used
for optional function arguments and optional<>. The analogy
should help users become familiar with optional<>.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk