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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.