From 4b17bf95f2d367116e45d73f2282390d8a688e9c Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 9 Sep 2014 23:12:35 +0100 Subject: move semantics --- c,cc/vector_move.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 c,cc/vector_move.cc (limited to 'c,cc') 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 +#include +#include +#include + +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.emplace_back(1); + a.emplace_back(1); + a.emplace_back(1); + vector 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; +} + -- cgit v1.2.3