rvalue中的对象是否引用了对象,是否引用了rvalue?

时间:2014-06-24 07:23:00

标签: c++ c++11 rvalue-reference

rvalue中的对象是否引用了对象,是否引用了rvalue?

struct A{
};

struct B{
   A a2;
};

//template<class B>
void test(B &&b){

    // 1. Is this the correct way?
    auto &&in3 = std::forward<B>(b).a2;
    std::cout << std::is_rvalue_reference<decltype(in3)>::value;
    // return true

    // 2. or this?
    auto &&in4 = b.a2;
    std::cout << std::is_rvalue_reference<decltype(in4)>::value;    
    // return false        
}

test(B());

http://coliru.stacked-crooked.com/a/bcf0f7dc4cc0440e

1 个答案:

答案 0 :(得分:7)

是的,右撇子的成员本身就是左撇子。这由DR 421

澄清

但这与此无关:

  

auto&amp;&amp; in4 = b.a2;

b不是左值,它是左值(简单的经验法则:它有一个名称)。

要恢复传递给forward

所需功能的值类别
相关问题