Is there a modification to the interface that can get the second call to work?
Or should I leave things as is?
I suspect the extra construction in the first case was designed that way on purpose so it is clear that ownership is being transferred.
#include <memory>
struct Bar { };
typedef std::unique_ptr<Bar> UPBar;
void foo1( UPBar p ) { }
void foo2( UPBar p ) { foo1( move( p )); }
void foo3( UPBar p ) { foo2( move( p )); }
void foo4( UPBar p ) { foo3( move( p )); }
int main(int argc, char** argv)
{
UPBar p( new Bar );
foo4( move( p )); // ok, but requires an extra construction vs line below
foo4( new Bar ); // fails: any modification to get this to work?
return 0;
}
Second Question: If I change all the parameters passed to RValue-References (&&), is there any disadvantage in doing so? In fact, should I ensure that all my std::unique_ptr<>
parameters are passed by RValue-References?