How to create a temporary when a const lvalue reference is used to initialize an rvalue reference

Viewed 41

Following code:

struct T {};
const T& foo();
void bar(T&& arg);

bar(T(foo()));

The last line is correct, but it uses T directly. If T is somewhat more complex (e.g. involving templates), then the line gets ugly. Since we have std::move and std::forward, I wonder if there is something similar in the standard lib for the above case. Something like

template<class T>
T make_temporary(const T& arg) { return arg; }

Provides the standard an appropriate solution?

0 Answers
Related