部分模板特化中的可变参数模板参数扩展
Variadic template argument expansion in partial template specialization
我有一个可变参数模板(出于测试目的禁用了非专用版本):
template <typename...>
std::enable_if_t<false> S;
我想部分专门化它,但由于某种原因它不起作用(Visual Studio 2017 RC:error C2275: 'x': illegal use of this type as an expression
,error C3544: '<unnamed-symbol>': parameter pack expects a type template argument
):
template<typename... x>
int S<int(x)...> = sizeof...(x);
我想要达到的效果可以近似为:
template<typename x1>
int S<int(x1)> = 1;
template<typename x1, typename x2>
int S<int(x1), int(x2)> = 2;
template<typename x1, typename x2, typename x3>
int S<int(x1), int(x2), int(x3)> = 3;
//etc
有没有办法让它起作用?
此版本适用于 http://webcompiler.cloudapp.net/
诀窍是将 int(T)
隐藏在它自己的自定义类型中:
template <typename T>
using FInt = int(T);
template <typename ... Ts>
int S = std::enable_if_t<(sizeof...(Ts) >= 0)>{};
template<typename ... Ts>
int S<FInt<Ts> ...> = sizeof...(Ts);
我有一个可变参数模板(出于测试目的禁用了非专用版本):
template <typename...>
std::enable_if_t<false> S;
我想部分专门化它,但由于某种原因它不起作用(Visual Studio 2017 RC:error C2275: 'x': illegal use of this type as an expression
,error C3544: '<unnamed-symbol>': parameter pack expects a type template argument
):
template<typename... x>
int S<int(x)...> = sizeof...(x);
我想要达到的效果可以近似为:
template<typename x1>
int S<int(x1)> = 1;
template<typename x1, typename x2>
int S<int(x1), int(x2)> = 2;
template<typename x1, typename x2, typename x3>
int S<int(x1), int(x2), int(x3)> = 3;
//etc
有没有办法让它起作用?
此版本适用于 http://webcompiler.cloudapp.net/
诀窍是将 int(T)
隐藏在它自己的自定义类型中:
template <typename T>
using FInt = int(T);
template <typename ... Ts>
int S = std::enable_if_t<(sizeof...(Ts) >= 0)>{};
template<typename ... Ts>
int S<FInt<Ts> ...> = sizeof...(Ts);