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); } 
2
  • Interesting note: value is not an Rvalue, and is, confusingly, an lvalue. stackoverflow.com/questions/14486367/… Commented Dec 17, 2020 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. Commented Dec 18, 2020 at 0:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.