summaryrefslogtreecommitdiff
path: root/libs/move/test/construct_forward.cpp
blob: bf4c5262342b6a463982bcbd6a81e543562de90e (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright David Abrahams, Vicente Botet, Ion Gaztanaga 2009-2011.
// 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/utility/enable_if.hpp>
#include "../example/movable.hpp"
#include "../example/copymovable.hpp"
#include <cstdio>

class non_movable
{
   public:
   non_movable()
   {}
};

template<class MaybeRvalue>
void catch_test(BOOST_RV_REF(MaybeRvalue) x
               #ifdef BOOST_NO_RVALUE_REFERENCES
               ,typename ::boost::enable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
               #endif   //BOOST_NO_RVALUE_REFERENCES
               )
{  (void)x;}

template<class MaybeRvalue>
void catch_test(BOOST_COPY_ASSIGN_REF(MaybeRvalue) x
               #ifdef BOOST_NO_RVALUE_REFERENCES
               ,typename ::boost::enable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
               #endif   //BOOST_NO_RVALUE_REFERENCES
               )

{  (void)x;}

template<class MaybeRvalue>
void catch_test(MaybeRvalue &x
               #ifdef BOOST_NO_RVALUE_REFERENCES
               ,typename ::boost::enable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
               #endif   //BOOST_NO_RVALUE_REFERENCES
               )
{  (void)x;}

               #ifdef BOOST_NO_RVALUE_REFERENCES
template<class MaybeRvalue>
void catch_test(const MaybeRvalue& x
               ,typename ::boost::disable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
               )
{  (void)x;}
               #endif   //BOOST_NO_RVALUE_REFERENCES

movable create_movable()
{  return movable(); }

copy_movable create_copy_movable()
{  return copy_movable(); }

non_movable create_non_movable()
{  return non_movable(); }


void catch_test()
{
   movable m;
   const movable constm;
   catch_test<movable>(boost::move(m));
   #ifdef BOOST_CATCH_CONST_RLVALUE
   catch_test<movable>(create_movable());
   #endif
   catch_test<movable>(m);
   catch_test<movable>(constm);
   copy_movable cm;
   const copy_movable constcm;
   catch_test<copy_movable>(boost::move(cm));
   catch_test<copy_movable>(create_copy_movable());
   catch_test<copy_movable>(cm);
   catch_test<copy_movable>(constcm);
   non_movable nm;
   const non_movable constnm;
   catch_test<non_movable>(boost::move(nm));
   catch_test<non_movable>(create_non_movable());
   catch_test<non_movable>(nm);
   catch_test<non_movable>(constnm);
}

template<class MaybeMovableOnly, class MaybeRvalue>
void function_construct(BOOST_FWD_REF(MaybeRvalue) x)
{
   //Moves in case Convertible is boost::rv<movable> copies otherwise
   //For C++0x perfect forwarding
   MaybeMovableOnly m(boost::forward<MaybeRvalue>(x));
}

void forward_test()
{
   movable m;
   function_construct<movable>(boost::move(m));
//   non_movable nm;
//   function_construct<non_movable>(boost::move(nm));
//   const non_movable cnm;
//   function_construct<non_movable>(cnm);
}

int main()
{
   catch_test();
   forward_test();
   return 0;
}