
9 Jan
2010
9 Jan
'10
8:42 a.m.
typedef boost::variant<derived_1, derived_2> variant_type;
void f() { variant_type v;
v = derived_1(); assert(boost::get<base>(&v)); // This will fail.
You can get the desired behaviour by applying a visitor.
I know that. I even admitted that in the post (at the end). But IMHO it does not change anything. boost::get can be implemented as a visitor (and in fact is implemented so) but still is provided as a function for convenience. Obviously it would not be wise to provide a function wrapper for each and every visitor. However the extended "get" I proposed is unique in its ways. Firstly it extends function already present in Boost. Secondly it provides for variant a feature available in union. Adam Badura