看这篇文章http://thbecker.net/articles/rvalue_references/section_07.html . 我们可以找到这句话:
Firstly, if factory had not one, but several arguments, you would have to provide overloads for all combinations of non-const and const reference for the various arguments.
我的问题是,为什么我们需要为非 const 和 const 引用的组合提供重载?在我看来,我们只需要为 const 引用提供重载,因为我们可以将右值和左值都传递给 const 引用。
最佳答案
如果您转发到的函数采用常量,那么您需要传递一个常量引用。如果您转发的值是非常量,那么您需要传递一个非常量,因为您将需要转发到非常量函数。
关于c++ - Perfect Forwarding - 关于 const 和 non-const ref 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54428572/