#include <iostream>
#include <utility>
#include <vector>
int i = 0;
struct A
{
A() : j( ++i )
{
std::cout<<"constructor "<<j<<std::endl;
}
A( const A & c) : j(c.j)
{
std::cout<<"copy "<<j<<std::endl;
}
A( const A && c) : j(c.j)
{
std::cout<<"move "<<j<<std::endl;
}
~A()
{
std::cout<<"destructor "<<j<<std::endl;
}
int j;
};
typedef std::vector< A > vec;
void foo( vec & v )
{
v.push_back( std::move( A() ) );
}
int main()
{
vec v;
v.reserve(2);
foo( v );
foo( v );
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHZlY3Rvcj4KCmludCBpID0gMDsKc3RydWN0IEEKewogICAgQSgpIDogaiggKytpICkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQ8PCJjb25zdHJ1Y3RvciAiPDxqPDxzdGQ6OmVuZGw7CiAgICB9CiAgICBBKCBjb25zdCBBICYgYykgOiBqKGMuaikKICAgIHsKICAgICAgICBzdGQ6OmNvdXQ8PCJjb3B5ICI8PGo8PHN0ZDo6ZW5kbDsKICAgIH0KICAgIEEoIGNvbnN0IEEgJiYgYykgOiBqKGMuaikKICAgIHsKICAgICAgICBzdGQ6OmNvdXQ8PCJtb3ZlICI8PGo8PHN0ZDo6ZW5kbDsKICAgIH0KICAgIH5BKCkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQ8PCJkZXN0cnVjdG9yICI8PGo8PHN0ZDo6ZW5kbDsKICAgIH0KCiAgICBpbnQgajsKfTsKCnR5cGVkZWYgc3RkOjp2ZWN0b3I8IEEgPiB2ZWM7Cgp2b2lkIGZvbyggdmVjICYgdiApCnsKICAgIHYucHVzaF9iYWNrKCBzdGQ6Om1vdmUoIEEoKSApICk7Cn0KCmludCBtYWluKCkKewogICAgdmVjIHY7CiAgICB2LnJlc2VydmUoMik7CgogICAgZm9vKCB2ICk7CiAgICBmb28oIHYgKTsKfQ==