introom
V2EX  ›  问与答

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

  •  
  •   introom · Oct 19, 2016 · 1509 views
    This topic created in 3529 days ago, the information mentioned may be changed or developed.

    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 呢?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1575 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 16:23 · PVG 00:23 · LAX 09:23 · JFK 12:23
    ♥ Do have faith in what you're doing.