Search code examples
c++11move-semanticsforwarding-referenceprvalue

Move a prvalue into function template uref argument or not?


my question is if it would make sense to std::move (or not) a prvalue into a catch-all function template which accordingly takes a universal reference T&& in its signature. Also I would like to know if copy-move elision/RVO is playing a role in this decision.

Question(s): Will reference collapsing result in foo being called with T&& (rvalue reference) with or w/o std::move and does RVO have any effect on that (or that on RVO)?

template < typename T >
void foo(T&& arg)
{
    //Whatever..
}

A func()
{
    A m;
    return m;
}

// called anywhere you like
foo(std::move(func()));

Thanks in advance Sam


Solution

  • That move has no effect whatsoever other than making the compiler, the optimizer, and the readers of your code do more pointless work.

    Don't do it.