
I just started using boost::optional, and this proved to be generically useful, but I believe is currently not in boost::optional: template< class T, class Tcompatible > bool optional_assign( T& t, boost::optional<Tcompatible> const& optt ) { if( optt ) { t=*optt; return true; } else { return false; } } so you can write boost::optional< TMyValue > TryToGetT(); T t; if( !optional_assign( t, TryToGetT () ) { ... other way to get t ... } instead of the more verbose: boost::optional< TMyValue > TryToGetT(); T t; boost::optional< TMyValue > const& optt=TryToGetT(); if( optt ) { t=*optt; } else { ... other way to get t ... } get_optional_value_or is similar, but the alternative must be an expression and is eagerly evaluated, both of which may be undesirable. Arno -- Dr. Arno Schoedl · aschoedl@think-cell.com Technical Director think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany http://www.think-cell.com · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091 Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229