2012-10-27 24 views
4

如何識別boost :: fusion向量中的類型?如何識別boost融合向量中的類型

例如

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

然後東西,會讓我確定v[0]爲爲double類型和v[2]stringint類型,v[1]

謝謝。

+0

沒有這樣的東西'v [0]'因爲你需要一個編譯時構造。你嘗試了什麼,你想做什麼? –

回答

6

爲了提取從需要使用boost::fusion::at_c,像這樣的boost::fusion::vector的元素:

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

類型在位置N是:

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

啊,這可能也適用,謝謝。 – arlogb

0

This link描述了我正在嘗試做的事情。

具體而言,以下就是我想實現:

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; 
}; 

其中T是升壓::融合載體的一個std ::向量。