diff options
author | Patrick Simianer <p@simianer.de> | 2014-09-09 23:12:35 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-09-09 23:12:35 +0100 |
commit | 4b17bf95f2d367116e45d73f2282390d8a688e9c (patch) | |
tree | f454e4cc02b4c38265304344f87e89bcfc800500 | |
parent | 626c2cd921e7442c20ac1be7be0b9ecb44d00c95 (diff) |
move semantics
-rw-r--r-- | c,cc/vector_move.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/c,cc/vector_move.cc b/c,cc/vector_move.cc new file mode 100644 index 0000000..1167270 --- /dev/null +++ b/c,cc/vector_move.cc @@ -0,0 +1,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; +} + |