|
Boost : |
From: Eric Friedman (ebf_at_[hidden])
Date: 2003-09-01 01:43:39
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk