summaryrefslogtreecommitdiff
path: root/c,cc/vector_move.cc
blob: 1167270dd554315e957a5c5eb31943ef33e96b0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;


struct A {
  int d;

  A(int i) : d(i) {}

  A(A&& a) : d(a.d) { a.d = 0; }
};

int
main(void)
{
  vector<A> a;
  a.emplace_back(1);
  a.emplace_back(1);
  a.emplace_back(1);
  vector<A> b;
  b.emplace_back(2);

  cout << a.size() << endl;
  move(b.begin(), b.end(), back_inserter(a));
  cout << a.size() << endl;
  cout << b[0].d << endl;

  return 0;
}