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