summaryrefslogtreecommitdiff
path: root/libs/move/test/back_move_inserter.cpp
blob: ca4720bf3d25d8145351ef1f02652a750d0d2807 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright David Abrahams, Vicente Botet, Ion Gaztanaga 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/move for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/move/move.hpp>
#include <boost/container/deque.hpp>
#include <boost/container/list.hpp>
#include <boost/container/stable_vector.hpp>
#include "../example/movable.hpp"

template<class Container>
int move_test()
{
   //Default construct 10 movable objects
   Container v(10);

   //Test default constructed value
   if(v.begin()->moved()){
      return 1;
   }

   //Move values
   Container v2;
   std::copy(v.begin(), v.end(), boost::back_move_inserter(v2));

   //Test values have been moved
   if(!v.begin()->moved()){
      return 1;
   }

   if(v2.size() != 10){
      return 1;
   }

   if(v2.begin()->moved()){
      return 1;
   }
   return 0;
}

int main()
{
   namespace bc = ::boost::container;

   if(move_test< bc::vector<movable> >()){
      return 1;
   }
   if(move_test< bc::list<movable> >()){
      return 1;
   }
   if(move_test< bc::stable_vector<movable> >()){
      return 1;
   }
   return 0;
}