Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2004-03-29 16:23:24


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.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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