Why does this need an explicit std::move?

后端 未结 4 831
失恋的感觉
失恋的感觉 2020-12-18 20:57

Let\'s say I got a Foo class containing an std::vector constructed from std::unique_ptr objects of another class, Bar.

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 21:36

    bar is defined as an rvalue-reference, but its value-category is an lvalue. This is so because the object has a name. If it has a name, it's an lvalue. Therefore an explicit std::move is necessary because the intention is to get rid of the name and return an xvalue (eXpiring-rvalue).

提交回复
热议问题