【问题标题】:Type traits of float (int) constfloat (int) const 的类型特征
【发布时间】:2016-03-29 00:07:04
【问题描述】:

当我尝试自己实现类型特征时,我将结果与 std<type_traits> 进行了比较。我试图检查float (int) const 类型的类型特征,我认为它应该是函数。我得到了奇怪的结果,所以我尝试将这种类型传递给 std 类型特征。这是我的测试代码:

std::cout << std::is_function<float (int) const>::value;
std::cout << std::is_compound<float(int) const>::value;
std::cout << std::is_pointer<float(int)const>::value;
std::cout << std::is_class<float(int)const>::value;
std::cout << std::is_union<float(int)const>::value;
std::cout << std::is_member_pointer<float(int)const>::value;
std::cout << std::is_array<float(int)const>::value;
std::cout << std::is_scalar<float(int)const>::value;
std::cout << std::is_enum<float(int)const>::value;
std::cout << std::is_object<float(int)const>::value;

此测试的输出如下:

0100000001

意思是这个类型是复合&对象,而不是标量。根据http://www.cplusplus.com/reference/type_traits/,应该是类、联合或数组,都不是真的。这种类型的正确结果应该是什么?我正在使用 MSVC 2015。

【问题讨论】:

  • 您链接的页面的哪一部分让您认为float(int) const 应该是类、联合或数组类型?
  • 它是复合的、对象的但不是标量的事实只剩下这三种可能性。
  • 另外,您已经发布了 10 行,每行应该打印出一位输出,但只有 8 位输出。您的代码和输出不匹配。
  • float(int) const 不应该是对象类型。它是一种函数类型。 MSVC 2015 真的说它不是函数类型吗?输出应该类似于this
  • 是的,确实如此。所以肯定是MSVC库的bug。

标签: c++ templates typetraits


【解决方案1】:

这是 MSVS 实现中的一个错误; float(int) const is both function and compound.

在 Connect 上提出它,如果它不存在(它似乎不存在)。

我怀疑尾随的 const(应该被忽略/剥离)正在丢东西。

【讨论】:

  • 似乎在模板部分特化函数的情况下,remove_cv 不起作用。 GCC 实现专门针对每种可能的 cv 组合。
猜你喜欢
  • 2021-12-15
  • 2014-05-25
  • 2019-02-24
  • 1970-01-01
  • 2019-06-24
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多