Reputation: 9432
I would like to get the underlying type of a variant. For example"something similar to this:
typedef boost::variant< shared_ptr<int> , shared_ptr<float> > VType;
typedef VType::get<0>::type TYPE1; // TYPE1 = shared_ptr<int>
TYPE1 value = new std::remove_pointer<TYPE1>::type() // make a new shared_ptr<int>
Any ideas how to achieve this with boost?
Upvotes: 1
Views: 73
Reputation: 254471
The variant
contains an MPL sequence called types
, which you can use to access the types.
#include <boost/mpl/at.hpp>
typedef typename boost::mpl::at_c<VType::types, 0>::type TYPE1;
Upvotes: 3