Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2002-12-10 14:12:52


----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
To: "Boost mailing list" <boost_at_[hidden]>
Sent: Tuesday, December 10, 2002 3:33 PM
Subject: Re: [boost] Formal review: Optional library

> From: "Fernando Cacciola" <fernando_cacciola_at_[hidden]>
> > > I don't think that optional<bool> is an important use case (outside of
> > > generic contexts) since optional<bool> is simply a tri-state type with
> an
> > > inconvenient interface.
> > >
> > Good point. I've been using optional<bool> long before tribool existed.
> > Now I might replace optional<bool> with tribool; but, a user still
> > can have optional<bool>.
>
> But what is gained by using optional<bool> instead of
>
> enum optional_bool { uninitialized, true_, false_ };
>
> ?
>
> Especially if you take into account that with the enum you can use
> descriptive identifiers. It's a good idea to use enums in interfaces even
> for non-optional bools when the meaning of 'true' isn't immediately
> apparent.
>
I understand your reasoning, but what do you suggest?
Leaving optional<bool> inherently unsafe? with a strong remark on the
documentation that you should been using optional<bool> in the first place?
Or specializing optional<bool>, perhaps, with a empty definition so that it
is explicitly banned?

It worries me that any of the options above will create problems when
optional is used generically, as in optional<T>.

Fernando Cacciola


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