Dave Gomboc wrote: [snip] > I don't like get() because I cannot write x.get() when x is a POD. This > would mean I have to support nilable<T> and T with different code, > which is exactly what I'm trying to avoid.
Why not overload boost::get again for optional? This would certainly improve consistency with variant. For instance: optional<T> opt; ... T& r = boost::get<T>(opt); // throws bad_get if opt empty T* p = boost::get<T>(&opt); // p is null if opt empty In the same line, we could make optional visitable: class my_visitor : public boost::static_visitor<> { void operator()(boost::empty) const { ... } void operator()(const T& operand) const { ... } }; boost::apply_visitor( my_visitor(), opt ); Support for visitation would also allow seamless integration with the typeswitch construct I'm working on: switch_(opt) = case_<boost::empty>( ... ) = case_<T>( ... ) ; I don't have experience with boost::optional, so I don't know how any of the above would require changes to its interface or concepts. My two cents, Eric _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost