• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 class non_movable
20 {
21    public:
non_movable()22    non_movable()
23    {}
24 };
25 
26 template<class MaybeRvalue>
catch_test(BOOST_RV_REF (MaybeRvalue),typename::boost::enable_if<::boost::has_move_emulation_enabled<MaybeRvalue>>::type * =0)27 void 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 
34 template<class MaybeRvalue>
catch_test(BOOST_COPY_ASSIGN_REF (MaybeRvalue),typename::boost::enable_if<::boost::has_move_emulation_enabled<MaybeRvalue>>::type * =0)35 void 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 
43 template<class MaybeRvalue>
catch_test(MaybeRvalue &,typename::boost::enable_if<::boost::has_move_emulation_enabled<MaybeRvalue>>::type * =0)44 void 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
52 template<class MaybeRvalue>
catch_test(const MaybeRvalue &,typename::boost::disable_if<::boost::has_move_emulation_enabled<MaybeRvalue>>::type * =0)53 void 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 
create_movable()59 movable create_movable()
60 {  return movable(); }
61 
create_copy_movable()62 copy_movable create_copy_movable()
63 {  return copy_movable(); }
64 
create_non_movable()65 non_movable create_non_movable()
66 {  return non_movable(); }
67 
68 
catch_test()69 void catch_test()
70 {
71    movable m;
72    const movable constm;
73    catch_test<movable>(boost::move(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(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(nm));
88    catch_test<non_movable>(create_non_movable());
89    catch_test<non_movable>(nm);
90    catch_test<non_movable>(constnm);
91 }
92 
93 template<class MaybeMovableOnly, class MaybeRvalue>
function_construct(BOOST_FWD_REF (MaybeRvalue)x)94 void 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 
forward_test()101 void forward_test()
102 {
103    movable m;
104    function_construct<movable>(boost::move(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 
main()111 int main()
112 {
113    catch_test();
114    forward_test();
115    return 0;
116 }
117