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)
7 #ifndef BOOST_COROUTINES2_DETAIL_PULL_COROUTINE_IPP
8 #define BOOST_COROUTINES2_DETAIL_PULL_COROUTINE_IPP
13 #include <boost/assert.hpp>
14 #include <boost/config.hpp>
16 #include <boost/coroutine2/detail/config.hpp>
17 #include <boost/coroutine2/detail/create_control_block.ipp>
18 #include <boost/coroutine2/detail/disable_overload.hpp>
19 #include <boost/coroutine2/fixedsize_stack.hpp>
20 #include <boost/coroutine2/segmented_stack.hpp>
22 #ifdef BOOST_HAS_ABI_HEADERS
23 # include BOOST_ABI_PREFIX
27 namespace coroutines2 {
30 // pull_coroutine< T >
32 template< typename T >
33 pull_coroutine< T >::pull_coroutine( control_block * cb) noexcept :
37 template< typename T >
39 pull_coroutine< T >::has_result_() const noexcept {
40 return nullptr != cb_->other->t;
43 template< typename T >
44 template< typename Fn,
47 pull_coroutine< T >::pull_coroutine( Fn && fn) :
48 pull_coroutine{ default_stack(), std::forward< Fn >( fn) } {
51 template< typename T >
52 template< typename StackAllocator, typename Fn >
53 pull_coroutine< T >::pull_coroutine( StackAllocator salloc, Fn && fn) :
54 cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } {
55 if ( ! cb_->valid() ) {
61 template< typename T >
62 pull_coroutine< T >::~pull_coroutine() noexcept {
63 if ( nullptr != cb_) {
68 template< typename T >
69 pull_coroutine< T >::pull_coroutine( pull_coroutine && other) noexcept :
74 template< typename T >
76 pull_coroutine< T >::operator()() {
81 template< typename T >
82 pull_coroutine< T >::operator bool() const noexcept {
83 return nullptr != cb_ && cb_->valid();
86 template< typename T >
88 pull_coroutine< T >::operator!() const noexcept {
89 return nullptr == cb_ || ! cb_->valid();
92 template< typename T >
94 pull_coroutine< T >::get() noexcept {
95 return std::move( cb_->get() );
99 // pull_coroutine< T & >
101 template< typename T >
102 pull_coroutine< T & >::pull_coroutine( control_block * cb) noexcept :
106 template< typename T >
108 pull_coroutine< T & >::has_result_() const noexcept {
109 return nullptr != cb_->other->t;
112 template< typename T >
113 template< typename Fn,
116 pull_coroutine< T & >::pull_coroutine( Fn && fn) :
117 pull_coroutine{ default_stack(), std::forward< Fn >( fn) } {
120 template< typename T >
121 template< typename StackAllocator, typename Fn >
122 pull_coroutine< T & >::pull_coroutine( StackAllocator salloc, Fn && fn) :
123 cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } {
124 if ( ! cb_->valid() ) {
130 template< typename T >
131 pull_coroutine< T & >::~pull_coroutine() noexcept {
132 if ( nullptr != cb_) {
137 template< typename T >
138 pull_coroutine< T & >::pull_coroutine( pull_coroutine && other) noexcept :
143 template< typename T >
144 pull_coroutine< T & > &
145 pull_coroutine< T & >::operator()() {
150 template< typename T >
151 pull_coroutine< T & >::operator bool() const noexcept {
152 return nullptr != cb_ && cb_->valid();
155 template< typename T >
157 pull_coroutine< T & >::operator!() const noexcept {
158 return nullptr == cb_ || ! cb_->valid();
161 template< typename T >
163 pull_coroutine< T & >::get() noexcept {
168 // pull_coroutine< void >
171 pull_coroutine< void >::pull_coroutine( control_block * cb) noexcept :
175 template< typename Fn,
178 pull_coroutine< void >::pull_coroutine( Fn && fn) :
179 pull_coroutine{ default_stack(), std::forward< Fn >( fn) } {
182 template< typename StackAllocator, typename Fn >
183 pull_coroutine< void >::pull_coroutine( StackAllocator salloc, Fn && fn) :
184 cb_{ create_control_block< control_block >( salloc, std::forward< Fn >( fn) ) } {
185 if ( ! cb_->valid() ) {
192 pull_coroutine< void >::~pull_coroutine() noexcept {
193 if ( nullptr != cb_) {
199 pull_coroutine< void >::pull_coroutine( pull_coroutine && other) noexcept :
205 pull_coroutine< void > &
206 pull_coroutine< void >::operator()() {
212 pull_coroutine< void >::operator bool() const noexcept {
213 return nullptr != cb_ && cb_->valid();
218 pull_coroutine< void >::operator!() const noexcept {
219 return nullptr == cb_ || ! cb_->valid();
224 #ifdef BOOST_HAS_ABI_HEADERS
225 # include BOOST_ABI_SUFFIX
228 #endif // BOOST_COROUTINES2_DETAIL_PULL_COROUTINE_IPP