2
我想拿出一個通用模板來合併一個元組中的元組或列表的類型列表。編譯時出現錯誤。C++ 0x合併元組
template<typename... Types>
struct merge_tuples{ typedef std::tuple<> type;};
template<typename Type>
struct merge_tuples<Type> {
typedef std::tuple<Type> type;
};
template<typename...Types>
struct merge_tuples<std::tuple<Types...>> {
typedef std::tuple<Types...> type;
};
template<typename...Types1,typename...Types2>
struct merge_tuples<std::tuple<Types1...>,std::tuple<Types2...>> {
typedef std::tuple<Types1...,Types2...> type;
};
template<typename...Types1,typename...Types2,typename...Rest>
struct merge_tuples<std::tuple<Types1...>,std::tuple<Types2...>,Rest...> {
typedef decltype(merge_tuples<std::tuple<Types1...,Types2...>,decltype(merge_tuples<Rest...>::type)>::type) type;
};
template<typename...Types1,typename Type>
struct merge_tuples<std::tuple<Types1...>,Type> {
typedef std::tuple<Types1...,Type> type;
};
typedef std::tuple<int,double> int_double;
typedef merge_tuples<int_double,int_double,int_double>::type megred;
我得到的錯誤是以下
lalr_grammar.cpp:152:97: error: unexpected type name 'type': expected expression
typedef decltype(merge_tuples<std::tuple<Types1...,Types2...>,decltype(merge_tuples<Rest...>::type)>::type) type;
^
lalr_grammar.cpp:420:11: note: in instantiation of template class 'merge_tuples<std::__1::tuple<int, double>, std::__1::tuple<int, double>, std::__1::tuple<int, double> >' requested here
typedef merge_tuples<int_double,int_double,int_double>::type megred;
什麼錯誤?當你想要答案時,你爲什麼不給它,讓我們更難? – Nobody
'std :: tuple_cat'已經做了你想做的事情嗎? (我不確定什麼'merge_tuples'實際上)。 –
merge_tuples將從元組或類型列表中創建一個新的元組 tuple_cat似乎沒有做我想要的東西我會研究它agian – James