News for hackers. Stuff that matters.
Re:C++: Return value optimization vs. std::move by mgraczyk on Monday July 20, 2015 @12:34PM (#9917168)
This doesn't help to solve the original problem of avoiding the copy. Your calls to

    big_object_ptr.reset(...)
will cause the BigObject copy constructor to be called. The object pointed to by unique_ptr does not have the same storage as the objects "foo" and "bar". At the very least, you need to do

    big_object_ptr.reset(std::move(foo));
which will cause foo to be moved into the unique_ptr's storage.

In code like this, you should just use make_unique, in which case the BigObject is constructed in place, and unique_ptr can be RVO'ed:

    if (...) {
        return make_unique<BigObject>(...);
    } else ...
Re:C++: Return value optimization vs. std::move by thrownaway2424 on Monday July 20, 2015 @12:47PM (#9917250)
Yeah I realized after the fact that the example is pointless, but I was trying to adhere to the original post, which is also pointless. Why would you construct two BigObject when you know you will discard one of them unused? It's dumb.