Say I have an object a of type A.
If I want to move this to a function foo(A)
.
One option is to do foo(std::move(a))
, which will invoke the move constructor.
But, let's say I am using a class over which I don't have control. If I still want to move the type, won't this suffice?
std::unique_ptr<A> a_ptr(new A());
foo(std::move(a_ptr));
with foo
changed to accepting a unique_ptr.
Aren't the two similar (with the small overhead of using a smart pointer in the second case)?