6
我曾经看过一个关于汽车的类型推演规则的视频和decltype斯科特迈尔斯解释......他解释以下decltype(rvalue expr)的类型演绎规则是什么?
// decltype(lvalue expr) => reference to the type of the expression
// decltype(lvalue name) => type of the name
我理解这些规则......但是他没有解释以下
// decltype(rvlaue expr) => ???
所以,我想通过练习可以这么理解我做了以下
int x = 8;
int func(); // calling this function is rvlaue expr ...
decltype(32) t1 = 128; // Ok t1 is int
decltype(64) t2 = x; // Ok t2 is int
decltype(func()) t3 = x; // Ok t3 is int ... obviously
现在魔术
decltype(std::move(x)) t4 = x; // Error t4 is int&& ... compiler says
不是std :: move(x)一个右值表达式?为什么decltype推导t4为int & &不只是int像上面的例子? 右值表达式的decltype类型推导的规则是什么?
注'的std :: move'的签名:'的std :: remove_reference_t ::类型&&移动(T &&);'它返回一个右值引用,而不是价值。 –
Jarod42
可能刚刚咨询过一个参考文献。Google需要十秒左右的文档。 –