我正在玩弄 SFINAE,我尝试检查我的输入是否由各种类型的输入组成。 clang 提供的错误没有多大帮助。你有什么想法吗?
谢谢
struct IsFree
{
};
template <typename _Type, typename _State>
struct Input
{
};
template <typename... _Inputs>
struct Inputs
{
};
template <template <typename _Type, typename _State> class, typename... _Inputs>
struct Inputs<Input<_Type, _State>, _Inputs...> : public Inputs<_Inputs...>
{
};
其他地方:
auto temp = Inputs<Input<float, IsFree>, Input<float, IsFree>> {};
我开始使用 clang-5.0 和 -std=c++17 :
13 : <source>:13:21: error: use of undeclared identifier '_Type'
struct Inputs<Input<_Type, _State>, _Inputs...> : public Inputs<_Inputs...>
^
13 : <source>:13:35: error: expected a type
struct Inputs<Input<_Type, _State>, _Inputs...> : public Inputs<_Inputs...>
^
2 errors generated.
Compiler exited with result code 1
最佳答案
template <template <typename _Type, typename _State> class, typename... _Inputs>
struct Inputs<Input<_Type, _State>, _Inputs...> : public Inputs<_Inputs...>
{
};
需要
template <typename _Type, typename _State, typename... _Inputs>
struct Inputs<Input<_Type, _State>, _Inputs...> : public Inputs<_Inputs...>
{
};
在模式中Input<_Type, _State>
_Type 和 _State 只是类型通配符,您只需要 template <typename, typename> class F
template 模板参数语法,如果您需要使用通配符匹配模板模板参数。在这种情况下,您将模板与名为 Input 的已知模板进行匹配
关于c++ - Variadic 模板模板和 SFINAE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47434046/