]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/move/test/construct_forward.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / move / test / construct_forward.cpp
CommitLineData
7c673cae
FG
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//////////////////////////////////////////////////////////////////////////////
20effc67 11
7c673cae 12#include <boost/move/utility_core.hpp>
20effc67 13
7c673cae
FG
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>
20effc67 27void catch_test(BOOST_RV_REF(MaybeRvalue)
7c673cae
FG
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 )
20effc67 32{}
7c673cae
FG
33
34template<class MaybeRvalue>
20effc67 35void catch_test(BOOST_COPY_ASSIGN_REF(MaybeRvalue)
7c673cae
FG
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
20effc67 41{}
7c673cae
FG
42
43template<class MaybeRvalue>
20effc67 44void catch_test(MaybeRvalue &
7c673cae
FG
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 )
20effc67 49{}
7c673cae
FG
50
51 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
52template<class MaybeRvalue>
20effc67 53void catch_test(const MaybeRvalue&
7c673cae
FG
54 ,typename ::boost::disable_if< ::boost::has_move_emulation_enabled<MaybeRvalue> >::type* = 0
55 )
20effc67 56{}
7c673cae
FG
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(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
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>(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
111int main()
112{
113 catch_test();
114 forward_test();
115 return 0;
116}