|
|
|
|
|
by daoxid
2633 days ago
|
|
> In general, if I need an rvalue and it's legal to convert the lvalue I have into an rvalue, the compiler should do it automatically. 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.