http://coliru.stacked-crooked.com/a/c795a5d2bb91ae32
#include <iostream>
struct X {
X(const char *) { std::cout << 1; }
X(const X &) { std::cout << 2; }
X(X &&) { std::cout << 3; }
};
X f(X a) {
return a;
}
X g(const char * b) {
X c(b);
return c;
}
int main() {
f("hello"); // 13
g("hello"); // 1
}
Is there any difference in the last line of function f(X a)
:
return a;
instead of return std::move(a);
?
Is it true that function f
doesn't have RVO but g
has NRVO?