完美的转发-这是什么一回事? [英] Perfect forwarding - what's it all about?

查看:70
本文介绍了完美的转发-这是什么一回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

使用转发的优势

有人可以向我解释什么是完美的

Could someone please explain to me what perfect forwarding is about?

推荐答案

http://www.justsoftwaresolutions.co.uk/cplusplus/rvalue_references_and_perfect_forwarding.html


为什么有用?好吧,这意味着函数模板可以使用std :: forward将其参数传递给另一个函数,同时保留函数参数的左值/右值性质。这称为完美转发,避免了过度复制,并避免了模板作者必须为lvalue和rvalue引用编写多个重载。

Why is this useful? Well, it means that a function template can pass its arguments through to another function whilst retaining the lvalue/rvalue nature of the function arguments by using std::forward. This is called "perfect forwarding", avoids excessive copying, and avoids the template author having to write multiple overloads for lvalue and rvalue references.

这篇关于完美的转发-这是什么一回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆