[C++-sig] Re: wrapping boost::optional
David Abrahams
dave at boost-consulting.com
Wed Jul 28 17:45:45 CEST 2004
"Neal D. Becker" <ndbecker2 at verizon.net> writes:
> What would be better, though, is that if the option is not initialized, it
> should return None in response to get. That would be more pythonic, no?
> Problem is, I don't know how to do that. Any hints?
template<typename T>
inline object get (boost::optional<T>& o) {
return o ? object() : object(o.get());
}
You'll have some issues with policies and ownership if you ever want
to wrap optional<T*> or optional<T&>, but this should be enough to get
you started.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list