:
class Thing {
public:
Thing();
~Thing();
Thing(const Thing&);
};
Thing f() {
Thing t;
return t;
}
Thing t2 = f();
struct A {
void *p;
constexpr A(): p(this) {}
};
constexpr A g() {
A a;
return a;
}
constexpr A a; constexpr A b = g();
void g() {
A c = g(); }
Here the criteria for elision can
eliminate
the copying of the local automatic object
t
into the result object for the function call
f(),
which is the global object
t2. Effectively, the construction of the local object
t
can be viewed as directly initializing the global
object
t2,
and that object's destruction will occur at program
exit
. Adding a move constructor to
Thing has the same effect, but it is the
move construction from the local automatic object to
t2 that is elided
. —
end example