How to identify types in fast merge vector

How could the types inside the boost :: fusion vector be identified?

eg.

fusion::vector<int, double, string> v; 

then something that would allow me to identify v[0] as an int , v[1] as a double and v[2] as a string .

Thanks.

+4
source share
2 answers

To extract an element from boost::fusion::vector , you need to use boost::fusion::at_c , for example:

 boost::fusion::vector<int, std::string> v(1, "hello"); std::cout << boost::fusion::at_c<0>(v) << std::endl; // prints 1 

Type in position N:

 boost::fusion::result_of::at_c<boost::fusion::vector<int, std::string>, 1>::type 
+6
source

This link describes what I was trying to do.

In detail, here is what I tried 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 the std :: vector of vectors boost :: fusion.

0
source

Source: https://habr.com/ru/post/1442487/


All Articles