简体   繁体   English

参数列表中的void_t有效,但不作为返回类型

[英]void_t in parameter list works but not as return type

There's an example on cppreference about the using alias. 关于使用别名的cppreference有一个例子。 This example fails because int has no member foo : 此示例失败,因为int没有成员foo

template<typename...> using void_t = void;
template<typename T> void_t<typename T::foo> f();
f<int>(); // error, int does not have a nested type foo

This is clear, but when I tried putting the void_t part in the parameter list it unexpectedly compiled: 这很清楚,但是当我尝试将void_t部分放在参数列表中时,它意外地编译了:

template<typename...> using void_t = void;
template<typename T> void f(void_t<typename T::foo>);
f<int>();

It compiles on clang but not in gcc. 它编译clang而不是gcc。 Is this a bug? 这是一个错误吗?

template<class...>struct voider{using type=void;};
template<class...Ts>using void_t=typename voider<Ts...>::type;

there is an ambiguity in the C++11 standard about whether non-used template parameters to template using aliases that are invalid types/expressions are a substitution failure or not. C ++ 11标准中存在一个含糊不清的问题,即使用无效类型/表达式别名的模板的未使用模板参数是否是替换失败。

gcc and clang interpreted the clause differently, which is what I think you are seeing. gcc和clang对这个条款的解释不同,这就是我认为你所看到的。 The above void_t should make it work the same in both gcc and clang. 上面的void_t应该使它在gcc和clang中都一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM