C++ 为什么“std::remove\u cv::type`不是类型?
我有两个版本的我期望是相同的功能,但gcc说版本1是有效的,而版本2给出了一个C++ 为什么“std::remove\u cv::type`不是类型?,c++,template-meta-programming,c++20,C++,Template Meta Programming,C++20,我有两个版本的我期望是相同的功能,但gcc说版本1是有效的,而版本2给出了一个 expected a type, got 'std::remove_cv<_Iter>::type' 及 关联 编辑是为了好玩,看起来clang和gcc在使用关键字的解释上有所不同。请参见您需要使用关键字来说明std::remove\u cv::type是一种类型 return std::is_same<u_underlying, typename std::remove_cv<V>:
expected a type, got 'std::remove_cv<_Iter>::type'
及
关联
编辑是为了好玩,看起来clang和gcc在使用关键字的解释上有所不同。请参见您需要使用关键字来说明std::remove\u cv::type是一种类型
return std::is_same<u_underlying, typename std::remove_cv<V>::type>::value;
// ^^^^^^^^
在using语句中,由于C++20,因此不再需要typename
在某些上下文中,只有类型名才能有效显示。在这些
在上下文中,假定依赖限定名命名类型,而不是
typename是必需的:
中出现的限定名称,其中最小的封闭类型id为:
...
中的类型id;
...
TL;dupe的DR,没有typename,该语言假定std::remove\u cv::type是一个值。@NathanOliver嗯,dupe不是很明显。typename已经在签名中了,为什么使用它会起作用,但当它是模板的一部分时却不起作用……typename总是在名称前面加前缀,所以使用u_underful=typename std::remove_cv::type@NathanOliver应该返回std::is_same::value;我重新开始了这个问题,因为它似乎集中在使用语句和返回语句时typename的用法之间的区别上。嗯,似乎clang仍然需要它。也许这就是缺少的功能?@Mikhail我认为clang还没有实现新功能。clang还没有实现,请参见参考资料中的。
template<typename U,typename V> constexpr inline auto is_same_rcv() noexcept
{
//version 2 doesn't work
using u_underlying = std::remove_cv<U>::type;
return std::is_same<u_underlying,std::remove_cv<V>::type>::value;
}
return std::is_same<u_underlying, typename std::remove_cv<V>::type>::value;
// ^^^^^^^^