V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
introom
V2EX  ›  问与答

std::forward 为什么要重载 rvalue reference?

  •  
  •   introom · 2016-10-19 15:14:10 +08:00 · 1096 次点击
    这是一个创建于 2762 天前的主题,其中的信息可能已经有所发展或是发生改变。

    20.2.4p1 参见这里: http://eel.is/c++draft/forward#1 给了这个 signature

    template <class t=""> constexpr T&& forward(remove_reference_t<t>&& t) noexcept;

    通畅 perfect forwarding 搭配 universal reference ,对于 std::forward<t>而言不都是接受 lvalue 然后根据<t>来 forward 出对应的 lvalue 或是 rvalue 么?也就是使用 20.2.4p1 中的第一个 signature 。

    对于第二个 signature ,如果我有 rvalue 了,我又何必多此一举重新 forward 出一个 rvalue 呢?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   947 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:11 · PVG 06:11 · LAX 15:11 · JFK 18:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.