您的位置:首页 > 编程语言 > C语言/C++

C++: Perfect Forwarding

2016-09-12 20:03 411 查看
Link:

Rvalue References and Perfect Forwarding in C++0x (https://www.justsoftwaresolutions.co.uk/cplusplus/rvalue_references_and_perfect_forwarding.html)

摘要:

std::forward is designed for use in a template function which takes its arguments by T&&, where T is a template parameter.

std::forward preserves the rvalue-ness of the arguments, so if your function was called with an rvalue then std::forward<T> provides an rvalue. If your function was called with an lvalue then std::forward<T> provides an lvalue.

This works because of the way T is deduced from a T&& parameter: T is deduced to be "X&", for an lvalue argument of type X, whereas it is deduced to be plain "X" for an rvalue argument.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: