Reputation: 681
How would one go about identifying the types inside a boost::fusion vector?
e.g.
fusion::vector<int, double, string> v;
then something that would let me identify v[0]
as being type int
, v[1]
as type double
and v[2]
as type string
.
Thanks.
Upvotes: 4
Views: 1136
Reputation: 2016
In order to extract an element from a boost::fusion::vector
you need to use boost::fusion::at_c
, like this:
boost::fusion::vector<int, std::string> v(1, "hello");
std::cout << boost::fusion::at_c<0>(v) << std::endl; // prints 1
The type at position N is:
boost::fusion::result_of::at_c<boost::fusion::vector<int, std::string>, 1>::type
Upvotes: 6
Reputation: 681
This link describes what I was trying to do.
In detail, the following is what I was trying to achieve:
template<int N, typename T>
struct a_struct{
typedef typename T::value_type etype;
typedef typename boost::fusion::result_of::value_at<etype, boost::mpl::int_<N> >::type a_type;
};
Where T is a std::vector of boost::fusion vectors.
Upvotes: 0