Summary of some knowledge points about C++ rvalues

I've been reading a lot about C++ rvalues lately due to work requirements. Combined with some of my practical experience, the following ten conclusions are drawn.

  1. There are two types of rvalues in C++: prvalues and xvalues.
  2. One of the effects of rvalue references is to extend the life cycle of rvalues
  3. Temporary objects are handled as rvalues
  4. Move constructors can bind rvalue non-constants whenever possible
  5. For an rvalue object, member functions are allowed to be called
  6. rvalues can be modified (which means they can be destroyed)
  7. An rvalue cannot be used as an lvalue, an lvalue can be used as an rvalue.
  8. A constant lvalue reference can be bound to an rvalue
  9. Functions that return rvalue references are bad in almost all cases
  10. Using std::move in return doesn't make things better in most cases, instead it prevents the compiler from optimizing the return value.

 

zh_CNZH-CN