const限定的许多好处之一是使API更容易理解,例如:
template<typename T> int function1(T const& in);
// clearly, the input won’t change through function1
Run Code Online (Sandbox Code Playgroud)
通过引入rvalue引用,可以从完美转发中受益,但通常会删除const限定符,例如:
template<typename T> int function2(T&& in);
// can explicitly forward the input if it's an rvalue
Run Code Online (Sandbox Code Playgroud)
除了文档之外,还有一种很好的方法来描述function2不会改变它的输入吗?