1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright David Abrahams, Vicente Botet, Ion Gaztanaga 2009-2012.
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
12#include <boost/move/utility_core.hpp>
13
14#include <boost/utility/enable_if.hpp>
15#include "../example/movable.hpp"
16#include "../example/copymovable.hpp"
17#include <cstdio>
18
19class non_movable
20{
21 public:
22 non_movable()
23 {}
24};
25
26template<class MaybeRvalue>
27void catch_test(BOOST_RV_REF(MaybeRvalue)
28 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
29 ,typename ::boost::enable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
30 #endif //BOOST_NO_CXX11_RVALUE_REFERENCES
31 )
32{}
33
34template<class MaybeRvalue>
35void catch_test(BOOST_COPY_ASSIGN_REF(MaybeRvalue)
36 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
37 ,typename ::boost::enable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
38 #endif //BOOST_NO_CXX11_RVALUE_REFERENCES
39 )
40
41{}
42
43template<class MaybeRvalue>
44void catch_test(MaybeRvalue &
45 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
46 ,typename ::boost::enable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
47 #endif //BOOST_NO_CXX11_RVALUE_REFERENCES
48 )
49{}
50
51 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
52template<class MaybeRvalue>
53void catch_test(const MaybeRvalue&
54 ,typename ::boost::disable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
55 )
56{}
57 #endif //BOOST_NO_CXX11_RVALUE_REFERENCES
58
59movable create_movable()
60{ return movable(); }
61
62copy_movable create_copy_movable()
63{ return copy_movable(); }
64
65non_movable create_non_movable()
66{ return non_movable(); }
67
68
69void catch_test()
70{
71 movable m;
72 const movable constm;
73 catch_test<movable>(boost::move(t&: m));
74 #ifdef BOOST_CATCH_CONST_RLVALUE
75 catch_test<movable>(create_movable());
76 #endif
77 catch_test<movable>(m);
78 catch_test<movable>(constm);
79 copy_movable cm;
80 const copy_movable constcm;
81 catch_test<copy_movable>(boost::move(t&: cm));
82 catch_test<copy_movable>(create_copy_movable());
83 catch_test<copy_movable>(cm);
84 catch_test<copy_movable>(constcm);
85 non_movable nm;
86 const non_movable constnm;
87 catch_test<non_movable>(boost::move(t&: nm));
88 catch_test<non_movable>(create_non_movable());
89 catch_test<non_movable>(nm);
90 catch_test<non_movable>(constnm);
91}
92
93template<class MaybeMovableOnly, class MaybeRvalue>
94void function_construct(BOOST_FWD_REF(MaybeRvalue) x)
95{
96 //Moves in case Convertible is boost::rv<movable> copies otherwise
97 //For C++0x perfect forwarding
98 MaybeMovableOnly m(boost::forward<MaybeRvalue>(x));
99}
100
101void forward_test()
102{
103 movable m;
104 function_construct<movable>(x: boost::move(t&: m));
105// non_movable nm;
106// function_construct<non_movable>(boost::move(nm));
107// const non_movable cnm;
108// function_construct<non_movable>(cnm);
109}
110
111int main()
112{
113 catch_test();
114 forward_test();
115 return 0;
116}
117

source code of boost/libs/move/test/construct_forward.cpp