From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2004-04-01 11:23:31


JOAQUIN LOPEZ MU?Z wrote:
> In the rationale of Boost.Optional, optional<T>
> is proposed as a convenient replacement of the
> time-honored practice of returning a
> std::pair<T,bool> with the bool indicating
> whether the T object is meaningful or not. Notably,
> this is precisely what some STL containers' memfuns
> do.
>
> So why not augment optional<T> with the following:
>
> optional<T>::optional(std::pair<T,bool> const&);
>
> and the obvious semantics? This would allow
> for instance to use optional<> like this:
>
> std::set<int> s;
> ...
> boost::optional<int> oi=s.insert(10);
> // oi is initialized iff insertion took place.
>
> Comments? Apologies if this has been discussed
> previously.
>
Hi,

Others have pointed out that the "bool" there doesn't mean ".first" is
uninitialized, but anyway I like your idea :-)
There are interfaces which do use pair<T,bool> with .second indicating if
.first actually exist, so I see your point.

Can anybody think of a reason for NOT adding it?

If no one complains, I'll add it.

Fernando Cacciola
SciSoft