class Item { };
class Wrapper
{
Item i;
Wrapper(const Item& mI) : i{mI} { }
Wrapper(Item&& mI) : i{std::move(mI)} { }
};
Item createItem()
{
Item result;
// ...
return result; // No `std::move` needed here
}
Wrapper createWrapper()
{
Wrapper result{createItem()}; // `std::move(createItem())` ?
return result;
}
createItem()
returns efficiently without having to call std::move
.
createWrapper()
uses the return value of createItem()
and wants to call the Wrapper::Wrapper(Item&&)
constructor.
Is it necessary to to use Wrapper result{std::move(createItem())};
or will Wrapper result{createItem()};
suffice?
There's no need for std::move
here. The value of a function call expression is already an rvalue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With