从属名称 T 被解析为非类型,但实例化产生类型

dependent-name T is parsed as a non-type, but instantiation yields a type

我知道有一些关于 SO 涉及这个主题的问题,但我还没有找到解决方案。

我想仅在其所有参数都是 pod 时启用函数 f

我有以下代码来执行此操作:

#include <type_traits>

template <typename... Conds>
struct and_ : std::true_type
{
};

template <typename Cond, typename... Conds>
struct and_<Cond, Conds...> :
    std::conditional<Cond::value, and_<Conds...>, std::false_type>::type
{
};

template <typename... T>
using are_all_pod = and_<std::is_pod<T>...>;

template<typename... Args,
         typename = typename std::enable_if<are_all_pod<Args...>::type>>
void f(Args ... args)
{
}

int main()
{
  f(1,2);
}

我确实收到以下错误:

main.cpp: In function ‘int main()’:
main.cpp:25:8: error: no matching function for call to ‘f(int, int)’
   f(1,2);
        ^
main.cpp:19:6: note: candidate: template<class ... Args, class> void f(Args ...)
 void f(Args ... args)
      ^
main.cpp:19:6: note:   template argument deduction/substitution failed:
main.cpp:18:10: error: dependent-name ‘and_<std::is_pod<T>...>::type’ is parsed as a non-type, but instantiation yields a type
          typename = typename std::enable_if<are_all_pod<Args...>::type>>
          ^
main.cpp:18:10: note: say ‘typename and_<std::is_pod<T>...>::type’ if a type is meant

我尝试遵循编译器的建议,但我得到了同样的错误。使用 gcc 5.2.1

std::enable_if<are_all_pod<Args...>::type> 没有意义。

将其更改为类似 std::enable_if<are_all_pod<Args...>::value, void>::type 的内容,程序将编译。