The Standard said that move constructor was applicable when function returns a value. Its not quite clear, because I thought when function returns a value, it creates a temporary object being constructed while function was executing. Of course, move constructor can be elided in order of the copy-elision process. But I'd like to consider the case where it doesn't:
#include <iostream>
struct X
{
int a = 42;
X();
X(const X&&, int t = 24);
};
X::X(){ }
X::X(const X&&, int g)
{
std::cout << g << std::endl;
}
X foo()
{
return X();
}
int main()
{
foo(); //move-constructor called
}
If we have a function, say
int foo()
{
int a = 5;
return a;
}
What actually happens within the memory when a function returns a value? Are there significant differences between the first and the second examples?