]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/coroutine2/detail/push_coroutine.ipp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / coroutine2 / detail / push_coroutine.ipp
1
2 // Copyright Oliver Kowalke 2014.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef BOOST_COROUTINES2_DETAIL_PUSH_COROUTINE_IPP
8 #define BOOST_COROUTINES2_DETAIL_PUSH_COROUTINE_IPP
9
10 #include <utility>
11
12 #include <boost/assert.hpp>
13 #include <boost/config.hpp>
14
15 #include <boost/coroutine2/detail/config.hpp>
16 #include <boost/coroutine2/detail/create_control_block.ipp>
17 #include <boost/coroutine2/detail/disable_overload.hpp>
18 #include <boost/coroutine2/fixedsize_stack.hpp>
19 #include <boost/coroutine2/segmented_stack.hpp>
20
21 #ifdef BOOST_HAS_ABI_HEADERS
22 # include BOOST_ABI_PREFIX
23 #endif
24
25 namespace boost {
26 namespace coroutines2 {
27 namespace detail {
28
29 // push_coroutine< T >
30
31 template< typename T >
32 push_coroutine< T >::push_coroutine( control_block * cb) noexcept :
33 cb_{ cb } {
34 }
35
36 template< typename T >
37 template< typename Fn,
38 typename
39 >
40 push_coroutine< T >::push_coroutine( Fn && fn) :
41 push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
42 }
43
44 template< typename T >
45 template< typename StackAllocator, typename Fn >
46 push_coroutine< T >::push_coroutine( StackAllocator && salloc, Fn && fn) :
47 cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
48 }
49
50 template< typename T >
51 push_coroutine< T >::~push_coroutine() {
52 if ( nullptr != cb_) {
53 cb_->deallocate();
54 }
55 }
56
57 template< typename T >
58 push_coroutine< T >::push_coroutine( push_coroutine && other) noexcept :
59 cb_{ nullptr } {
60 std::swap( cb_, other.cb_);
61 }
62
63 template< typename T >
64 push_coroutine< T > &
65 push_coroutine< T >::operator()( T const& t) {
66 cb_->resume( t);
67 return * this;
68 }
69
70 template< typename T >
71 push_coroutine< T > &
72 push_coroutine< T >::operator()( T && t) {
73 cb_->resume( std::forward< T >( t) );
74 return * this;
75 }
76
77 template< typename T >
78 push_coroutine< T >::operator bool() const noexcept {
79 return nullptr != cb_ && cb_->valid();
80 }
81
82 template< typename T >
83 bool
84 push_coroutine< T >::operator!() const noexcept {
85 return nullptr == cb_ || ! cb_->valid();
86 }
87
88
89 // push_coroutine< T & >
90
91 template< typename T >
92 push_coroutine< T & >::push_coroutine( control_block * cb) noexcept :
93 cb_{ cb } {
94 }
95
96 template< typename T >
97 template< typename Fn,
98 typename
99 >
100 push_coroutine< T & >::push_coroutine( Fn && fn) :
101 push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
102 }
103
104 template< typename T >
105 template< typename StackAllocator, typename Fn >
106 push_coroutine< T & >::push_coroutine( StackAllocator && salloc, Fn && fn) :
107 cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
108 }
109
110 template< typename T >
111 push_coroutine< T & >::~push_coroutine() {
112 if ( nullptr != cb_) {
113 cb_->deallocate();
114 }
115 }
116
117 template< typename T >
118 push_coroutine< T & >::push_coroutine( push_coroutine && other) noexcept :
119 cb_{ nullptr } {
120 std::swap( cb_, other.cb_);
121 }
122
123 template< typename T >
124 push_coroutine< T & > &
125 push_coroutine< T & >::operator()( T & t) {
126 cb_->resume( t);
127 return * this;
128 }
129
130 template< typename T >
131 push_coroutine< T & >::operator bool() const noexcept {
132 return nullptr != cb_ && cb_->valid();
133 }
134
135 template< typename T >
136 bool
137 push_coroutine< T & >::operator!() const noexcept {
138 return nullptr == cb_ || ! cb_->valid();
139 }
140
141
142 // push_coroutine< void >
143
144 inline
145 push_coroutine< void >::push_coroutine( control_block * cb) noexcept :
146 cb_{ cb } {
147 }
148
149 template< typename Fn,
150 typename
151 >
152 push_coroutine< void >::push_coroutine( Fn && fn) :
153 push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
154 }
155
156 template< typename StackAllocator, typename Fn >
157 push_coroutine< void >::push_coroutine( StackAllocator && salloc, Fn && fn) :
158 cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
159 }
160
161 inline
162 push_coroutine< void >::~push_coroutine() {
163 if ( nullptr != cb_) {
164 cb_->deallocate();
165 }
166 }
167
168 inline
169 push_coroutine< void >::push_coroutine( push_coroutine && other) noexcept :
170 cb_{ nullptr } {
171 std::swap( cb_, other.cb_);
172 }
173
174 inline
175 push_coroutine< void > &
176 push_coroutine< void >::operator()() {
177 cb_->resume();
178 return * this;
179 }
180
181 inline
182 push_coroutine< void >::operator bool() const noexcept {
183 return nullptr != cb_ && cb_->valid();
184 }
185
186 inline
187 bool
188 push_coroutine< void >::operator!() const noexcept {
189 return nullptr == cb_ || ! cb_->valid();
190 }
191
192 }}}
193
194 #ifdef BOOST_HAS_ABI_HEADERS
195 # include BOOST_ABI_SUFFIX
196 #endif
197
198 #endif // BOOST_COROUTINES2_DETAIL_PUSH_COROUTINE_IPP