File indexing completed on 2025-01-18 09:30:34
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_COROUTINES2_DETAIL_PULL_COROUTINE_IPP
0008 #define BOOST_COROUTINES2_DETAIL_PULL_COROUTINE_IPP
0009
0010 #include <algorithm>
0011 #include <utility>
0012
0013 #include <boost/assert.hpp>
0014 #include <boost/config.hpp>
0015
0016 #include <boost/coroutine2/detail/config.hpp>
0017 #include <boost/coroutine2/detail/create_control_block.ipp>
0018 #include <boost/coroutine2/detail/disable_overload.hpp>
0019 #include <boost/coroutine2/fixedsize_stack.hpp>
0020 #include <boost/coroutine2/segmented_stack.hpp>
0021
0022 #ifdef BOOST_HAS_ABI_HEADERS
0023 # include BOOST_ABI_PREFIX
0024 #endif
0025
0026 namespace boost {
0027 namespace coroutines2 {
0028 namespace detail {
0029
0030
0031
0032 template< typename T >
0033 pull_coroutine< T >::pull_coroutine( control_block * cb) noexcept :
0034 cb_{ cb } {
0035 }
0036
0037 template< typename T >
0038 bool
0039 pull_coroutine< T >::has_result_() const noexcept {
0040 return nullptr != cb_->other->t;
0041 }
0042
0043 template< typename T >
0044 template< typename Fn,
0045 typename
0046 >
0047 pull_coroutine< T >::pull_coroutine( Fn && fn) :
0048 pull_coroutine{ default_stack(), std::forward< Fn >( fn) } {
0049 }
0050
0051 template< typename T >
0052 template< typename StackAllocator, typename Fn >
0053 pull_coroutine< T >::pull_coroutine( StackAllocator && salloc, Fn && fn) :
0054 cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
0055 if ( ! cb_->valid() ) {
0056 cb_->deallocate();
0057 cb_ = nullptr;
0058 }
0059 }
0060
0061 template< typename T >
0062 pull_coroutine< T >::~pull_coroutine() {
0063 if ( nullptr != cb_) {
0064 cb_->deallocate();
0065 }
0066 }
0067
0068 template< typename T >
0069 pull_coroutine< T >::pull_coroutine( pull_coroutine && other) noexcept :
0070 cb_{ nullptr } {
0071 std::swap( cb_, other.cb_);
0072 }
0073
0074 template< typename T >
0075 pull_coroutine< T > &
0076 pull_coroutine< T >::operator()() {
0077 cb_->resume();
0078 return * this;
0079 }
0080
0081 template< typename T >
0082 pull_coroutine< T >::operator bool() const noexcept {
0083 return nullptr != cb_ && cb_->valid();
0084 }
0085
0086 template< typename T >
0087 bool
0088 pull_coroutine< T >::operator!() const noexcept {
0089 return nullptr == cb_ || ! cb_->valid();
0090 }
0091
0092 template< typename T >
0093 T
0094 pull_coroutine< T >::get() noexcept {
0095 return std::move( cb_->get() );
0096 }
0097
0098
0099
0100
0101 template< typename T >
0102 pull_coroutine< T & >::pull_coroutine( control_block * cb) noexcept :
0103 cb_{ cb } {
0104 }
0105
0106 template< typename T >
0107 bool
0108 pull_coroutine< T & >::has_result_() const noexcept {
0109 return nullptr != cb_->other->t;
0110 }
0111
0112 template< typename T >
0113 template< typename Fn,
0114 typename
0115 >
0116 pull_coroutine< T & >::pull_coroutine( Fn && fn) :
0117 pull_coroutine{ default_stack(), std::forward< Fn >( fn) } {
0118 }
0119
0120 template< typename T >
0121 template< typename StackAllocator, typename Fn >
0122 pull_coroutine< T & >::pull_coroutine( StackAllocator && salloc, Fn && fn) :
0123 cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
0124 if ( ! cb_->valid() ) {
0125 cb_->deallocate();
0126 cb_ = nullptr;
0127 }
0128 }
0129
0130 template< typename T >
0131 pull_coroutine< T & >::~pull_coroutine() {
0132 if ( nullptr != cb_) {
0133 cb_->deallocate();
0134 }
0135 }
0136
0137 template< typename T >
0138 pull_coroutine< T & >::pull_coroutine( pull_coroutine && other) noexcept :
0139 cb_{ nullptr } {
0140 std::swap( cb_, other.cb_);
0141 }
0142
0143 template< typename T >
0144 pull_coroutine< T & > &
0145 pull_coroutine< T & >::operator()() {
0146 cb_->resume();
0147 return * this;
0148 }
0149
0150 template< typename T >
0151 pull_coroutine< T & >::operator bool() const noexcept {
0152 return nullptr != cb_ && cb_->valid();
0153 }
0154
0155 template< typename T >
0156 bool
0157 pull_coroutine< T & >::operator!() const noexcept {
0158 return nullptr == cb_ || ! cb_->valid();
0159 }
0160
0161 template< typename T >
0162 T &
0163 pull_coroutine< T & >::get() noexcept {
0164 return cb_->get();
0165 }
0166
0167
0168
0169
0170 inline
0171 pull_coroutine< void >::pull_coroutine( control_block * cb) noexcept :
0172 cb_{ cb } {
0173 }
0174
0175 template< typename Fn,
0176 typename
0177 >
0178 pull_coroutine< void >::pull_coroutine( Fn && fn) :
0179 pull_coroutine{ default_stack(), std::forward< Fn >( fn) } {
0180 }
0181
0182 template< typename StackAllocator, typename Fn >
0183 pull_coroutine< void >::pull_coroutine( StackAllocator && salloc, Fn && fn) :
0184 cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
0185 if ( ! cb_->valid() ) {
0186 cb_->deallocate();
0187 cb_ = nullptr;
0188 }
0189 }
0190
0191 inline
0192 pull_coroutine< void >::~pull_coroutine() {
0193 if ( nullptr != cb_) {
0194 cb_->deallocate();
0195 }
0196 }
0197
0198 inline
0199 pull_coroutine< void >::pull_coroutine( pull_coroutine && other) noexcept :
0200 cb_{ nullptr } {
0201 std::swap( cb_, other.cb_);
0202 }
0203
0204 inline
0205 pull_coroutine< void > &
0206 pull_coroutine< void >::operator()() {
0207 cb_->resume();
0208 return * this;
0209 }
0210
0211 inline
0212 pull_coroutine< void >::operator bool() const noexcept {
0213 return nullptr != cb_ && cb_->valid();
0214 }
0215
0216 inline
0217 bool
0218 pull_coroutine< void >::operator!() const noexcept {
0219 return nullptr == cb_ || ! cb_->valid();
0220 }
0221
0222 }}}
0223
0224 #ifdef BOOST_HAS_ABI_HEADERS
0225 # include BOOST_ABI_SUFFIX
0226 #endif
0227
0228 #endif