
29 Mar
2004
29 Mar
'04
9:23 p.m.
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