码迷,mamicode.com
首页 > 编程语言 > 详细

C++: Perfect Forwarding

时间:2016-09-12 20:44:34      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

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.

 

C++: Perfect Forwarding

标签:

原文地址:http://www.cnblogs.com/hellohelloworld/p/5866062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!