我想要創建一個元函數,Append
採用模板類型,並將N
類型參數的數量T
添加到模板,例如,如果我調用Append<2, int, std::tuple<>>
我想獲得std::tuple<int, int>
。如何將模板參數重複附加到某個類型?
這裏是我試過:
#include <tuple>
template <int N, typename T, template <class> class Seq, typename... Args>
struct Append;
template <int N, typename T, template <class> class Seq, typename... Args>
struct Append<N, T, Seq<Args...>>
{
using type = Append<N-1, T, Seq<Args..., T>>::type;
};
template <typename T, template<class> class Seq, typename... Args>
struct Append<0, T, Seq<Args...>>
{
using type = Seq<Args...>;
};
// create a big tuple with N number of "int" types in it
using T = Append<2, int, std::tuple<>>::type;
int main()
{
return 0;
}
然而,當我嘗試編譯此我得到:
error: type/value mismatch at argument 3 in template parameter list for ‘template class Seq, class ... Args> struct Append’
我缺少什麼?
* error:模板模板參數的模板參數必須是類模板或類型別名模板*在'Seq> –
chris
2014-10-16 23:07:25