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需要十秒左右的文檔。 –