mardi 23 janvier 2018

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;
}

main()
{
    foo(std::move(func()));
}

Thanks in advance Sam

Aucun commentaire:

Enregistrer un commentaire