Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / move / test / move_iterator.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright David Abrahams, Vicente Botet, Ion Gaztanaga 2009.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // See http://www.boost.org/libs/move for documentation.
9 //
10 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/move/detail/config_begin.hpp>
12 #include <boost/move/iterator.hpp>
13 #include <boost/container/vector.hpp>
14 #include "../example/movable.hpp"
15
16 int main()
17 {
18    namespace bc = ::boost::container;
19    //Default construct 10 movable objects
20    bc::vector<movable> v(10);
21
22    //Test default constructed value
23    if(v[0].moved()){
24       return 1;
25    }
26
27    //Move values
28    bc::vector<movable> v2
29       (boost::make_move_iterator(v.begin()), boost::make_move_iterator(v.end()));
30
31    //Test values have been moved
32    if(!v[0].moved()){
33       return 1;
34    }
35
36    if(v2.size() != 10){
37       return 1;
38    }
39
40    //Move again
41    v.assign(boost::make_move_iterator(v2.begin()), boost::make_move_iterator(v2.end()));
42
43    //Test values have been moved
44    if(!v2[0].moved()){
45       return 1;
46    }
47
48    if(v[0].moved()){
49       return 1;
50    }
51
52    return 0;
53 }
54
55 #include <boost/move/detail/config_end.hpp>