c++ forward关键字 forward的由来:模板函数中的推导类型,作为另一函数的参数时,不管实参是什么类型,作为另一个参数的实参时,都变成了左值.因为C++里规定函数的形参就是左值,不过调用侧的实参是否是右值.所以,调用的另一个函数的形参即使用T&& arg来声明,传过去的也是左值,编译不过,因为不能自动把左值转化成右值,除非使用std::move.forward就是为了解决这个问题的. forward() 函数的作用:保持住实参的类型. include <iostream&…
std::forward argument: Returns an rvalue reference to arg if arg is not an lvalue reference; If arg is an lvalue reference, the function returns arg without modifying its type. std::forward:This is a helper function to allow perfect forwarding of arg…
std::forward argument: Returns an rvalue reference to arg if arg is not an lvalue reference; If arg is an lvalue reference, the function returns arg without modifying its type. std::forward:This is a helper function to allow perfect forwarding of arg…