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.
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++——算法基础之排序——堆排序
- C++基础(2)
- 极客班C++设计模式第一周课程笔记——常用模式(1)
- C++2
- C语言学习笔记 lesson5 浮点数类型及复习
- *c[];**cp[]和*cpp题目详解
- C++——算法基础之排序——选择排序
- 极客班C++设计模式第一周课堂笔记——设计原则
- {模板}C++读入优化
- C++——算法基础之排序——快速排序
- C++ new失败的处理
- C++继承:公有,私有,保护
- C++中重载与重写函数区别及虚函数(转载)
- Android ServiceManager源码(一)-- C语言部分
- 网易0912笔试题 暗黑字符串
- 高级软件工程师之路-c语言基本数据类型
- C++11:复习新增功能
- 9.12学习记录<<C和指针>>读后感
- 参考C语言的qsort函数实现一个一个能对任意数据类型(包括结构体)的数组进行排序的函数(里面用的不是快速排序)
- C语言之常用关键字的详解