Too*_*sie 6 c++ boost decltype xvalue c++11
C++标准对"xvalues"(N4762§7.2.1.4)进行了以下说明:
表达式是xvalue,如果它是:
- ...
- 类成员访问表达式,指定非引用类型的非静态数据成员,其中对象表达式是xvalue
考虑以下代码片段(使用Boost打印表达式的类型):
#include <iostream>
#include <boost/type_index.hpp>
using boost::typeindex::type_id_with_cvr;
struct X {
int var;
} x;
int main()
{
auto extended_type = type_id_with_cvr<decltype( std::move(x).var )>();
std::cout << extended_type.pretty_name() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是关于表达式std::move(x).var:
基于标准中的文本,我希望表达式是xvalue,但输出int不是int &&.
我在这里错过了什么?
小智 11
我的问题是关于表达式:
std::move(x).var基于标准中的文本,我希望表达式是xvalue,
它是.
但输出是
int,而不是int &&
那是因为decltype有两种形式.它可以提供有关如何声明名称的信息,或者可以提供有关表达式的类型和类别的信息.
由于std::move(x).var是会员访问,你得到前者.要获得后者,请使用decltype((std::move(x).var))(带双括号).
| 归档时间: |
|
| 查看次数: |
203 次 |
| 最近记录: |