【发布时间】:2014-01-28 13:22:13
【问题描述】:
可变模板模板参数接受任何模板:
template<typename T>
struct Test1 {
using type = int;
};
template<typename T, typename T1>
struct Test2 {
using type = char*;
};
template<template<typename...S> class BeCurry>
struct Currying {
};
using curry = Currying<Test1>;
using curry2 = Currying<Test2>;
我想要 Currying 模板模板类。
这意味着:如果参数接受一个模板参数为Test1,curry::apply<T>::type get Test1<T>::type。如果参数接受两个模板参数为Test2,curry2::apply<T0> 是“部分”模板,curry2::apply<T0>::apply<T1>::type get Test2<T0,T1>::type
这可以实现吗?因为我无法查询模板模板参数的内部参数数量:
template<template<typename... S> class BeCurry>
struct Currying {
enum { value = sizeof...(S) }; // error!
};
【问题讨论】:
-
请查看我的更新答案
标签: c++ templates c++11 variadic-templates