我正在与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
模板模板参数语法。在这种情况下,您要将模板与名为Input的已知模板进行匹配关于c++ - 可变参数模板和SFINAE,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47434046/