0

I've just started looking into move semantics and Rvalue references so I am learning as I go along, I was wondering whether a call to std::forward is needed when passing an Rvalue function parameter into a smart pointer?

void CreateUniquePtr(int&& value)
{
    std::unique_ptr<int> ptr = std::make_unique<int>(std::forward<int>(value));
}

vs

void CreateUniquePtr(int&& value)
{
    std::unique_ptr<int> ptr = std::make_unique<int>(value);
}
cmpbedes
  • 473
  • 1
  • 5
  • 13
  • Interesting note: `value` is not an Rvalue, and is, confusingly, an lvalue. https://stackoverflow.com/questions/14486367/why-do-you-use-stdmove-when-you-have-in-c11/14486705#14486705 – Mooing Duck Dec 17 '20 at 23:47
  • There is no reason to use `std::forward` outside of template cases. Using in any non-template case is pointless and possibly wrong. – ALX23z Dec 18 '20 at 00:00

0 Answers0