0

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

Navie
  • 164
  • 1
  • 8
  • Start by learning what `main()` returns... Anyway, this is a vague question or set of questions, and I can't believe that (A) it hasn't already been answered or (B) you couldn't write your own test for it. – underscore_d Jan 23 '18 at 22:35
  • I only wanted to emphasize a scope with the main function. The focus lies on the call and what exactly happens. Anyway, I correct it if that helps focusing on the question. – Navie Jan 23 '18 at 22:42
  • And yes, this is more of theoretical nature. I would like to know what is supposed to happen and therefore what to expect, not what my specific compiler is doing. This is purely research to me as I am not sure I understand the chain of events correctly. If you don‘t wanna help, that‘s fine. But maybe someone else is. And existing topics I found could not dissolve my doubts yet. – Navie Jan 23 '18 at 22:53

1 Answers1

1

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.

T.C.
  • 133,968
  • 17
  • 288
  • 421