by daoxid · 7y ago · 0 comments
This is already done in some places. Example:
std::unique_ptr<int> get_int() {
auto p = std::make_unique<int>(1);
// `p` is an lvalue but treated as an rvalue in the return statement.
// (This would not compile otherwise because `p` is not copyable.)
return p;
}I think copy initialization of an object will have the same will apply copy elision as well to result in the same performance, but I'm not entirely sure.
Because it'd break code. I explained in another comment here: https://news.ycombinator.com/item?id=19634423
Then that's an indictment of the decisions that led to such code being written in the first place.