Is it a good practice to return the r-value reference from the r-value ref-qualified method?
- 阅读更多 关于 Is it a good practice to return the r-value reference from the r-value ref-qualified method?
问题 As I can see the general rule is not to return r-value references from functions at all (except for rare special cases). But what about class methods? There is an example in the C++ standard library of returning r-value reference from the r-value ref-qualified method of the class (std::optional<T>::operator*() and std::optional<T>::value() methods of the std::optional<T> class). See sections 23.6.3 Class template optional [optional.optional] and 23.6.3.5 Observers [optional.observe] of the C+