Quick A: Because you want to not change the argument, or you want to forward it, respectively.
c++ rvalue reference and const qualifier
Among the many benefits of
const
qualification is to make an API more understandable, example:template<typename T> int function1(T const& in); // clearly, the input won’t change through function1With the introduction of rvalue references, one can benefit from perfect forwarding but often const qualifiers are removed, example:
template<typename T> int function2(T&& in); // can explicitly forward the input if it's an rvalueApart from documentation, is there a good way to describe that
function2
won’t change its input?
Add a Comment
Comments are closed.