【问题标题】:boost::call_traits - Why is gcc giving false for this?boost::call_traits - 为什么 gcc 为此给出错误?
【发布时间】:2012-06-09 22:10:36
【问题描述】:

示例:

#include <iostream>
#include <boost/call_traits.hpp>
#include <type_traits>

boost::call_traits<int>::param_type f()
{
        return 1;
}

int main()
{
        std::cout << std::boolalpha;
        std::cout <<
        std::is_const<boost::call_traits<int>::param_type>::value
        << std::endl; // true
        std::cout << std::is_const<decltype(f())>::value << std::endl; // false

}

问题:

除非,我做错了什么,我想我应该得到true,但gcc 4.7.0 输出false 为后者。有什么我遗漏的吗?

【问题讨论】:

    标签: c++ gcc boost c++11


    【解决方案1】:

    非类类型的右值永远不会被 const 限定。只有类类型的右值可以是 const 限定的。

    因此,即使函数f 被声明为返回const int,并且即使函数f 的类型是const int(),调用表达式f() 也是类型的右值(非-const) int.

    (在the new C++11 expression category taxonomy 中,调用表达式f()int 类型的prvalue。同样的规则适用:C++11 §3.10/4 声明“非类prvalues 总是有 cv 非限定类型。")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 2013-10-20
      • 2012-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多