Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:34

0001 
0002 //          Copyright Oliver Kowalke 2014.
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //    (See accompanying file LICENSE_1_0.txt or copy at
0005 //          http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_COROUTINES2_DETAIL_PUSH_COROUTINE_IPP
0008 #define BOOST_COROUTINES2_DETAIL_PUSH_COROUTINE_IPP
0009 
0010 #include <utility>
0011 
0012 #include <boost/assert.hpp>
0013 #include <boost/config.hpp>
0014 
0015 #include <boost/coroutine2/detail/config.hpp>
0016 #include <boost/coroutine2/detail/create_control_block.ipp>
0017 #include <boost/coroutine2/detail/disable_overload.hpp>
0018 #include <boost/coroutine2/fixedsize_stack.hpp>
0019 #include <boost/coroutine2/segmented_stack.hpp>
0020 
0021 #ifdef BOOST_HAS_ABI_HEADERS
0022 #  include BOOST_ABI_PREFIX
0023 #endif
0024 
0025 namespace boost {
0026 namespace coroutines2 {
0027 namespace detail {
0028 
0029 // push_coroutine< T >
0030 
0031 template< typename T >
0032 push_coroutine< T >::push_coroutine( control_block * cb) noexcept :
0033     cb_{ cb } {
0034 }
0035 
0036 template< typename T >
0037 template< typename Fn,
0038           typename
0039 >
0040 push_coroutine< T >::push_coroutine( Fn && fn) :
0041     push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
0042 }
0043 
0044 template< typename T >
0045 template< typename StackAllocator, typename Fn >
0046 push_coroutine< T >::push_coroutine( StackAllocator && salloc, Fn && fn) :
0047     cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
0048 }
0049 
0050 template< typename T >
0051 push_coroutine< T >::~push_coroutine() {
0052     if ( nullptr != cb_) {
0053         cb_->deallocate();
0054     }
0055 }
0056 
0057 template< typename T >
0058 push_coroutine< T >::push_coroutine( push_coroutine && other) noexcept :
0059     cb_{ nullptr } {
0060     std::swap( cb_, other.cb_);
0061 }
0062 
0063 template< typename T >
0064 push_coroutine< T > &
0065 push_coroutine< T >::operator()( T const& t) {
0066     cb_->resume( t);
0067     return * this;
0068 }
0069 
0070 template< typename T >
0071 push_coroutine< T > &
0072 push_coroutine< T >::operator()( T && t) {
0073     cb_->resume( std::forward< T >( t) );
0074     return * this;
0075 }
0076 
0077 template< typename T >
0078 push_coroutine< T >::operator bool() const noexcept {
0079     return nullptr != cb_ && cb_->valid();
0080 }
0081 
0082 template< typename T >
0083 bool
0084 push_coroutine< T >::operator!() const noexcept {
0085     return nullptr == cb_ || ! cb_->valid();
0086 }
0087 
0088 
0089 // push_coroutine< T & >
0090 
0091 template< typename T >
0092 push_coroutine< T & >::push_coroutine( control_block * cb) noexcept :
0093     cb_{ cb } {
0094 }
0095 
0096 template< typename T >
0097 template< typename Fn,
0098           typename
0099 >
0100 push_coroutine< T & >::push_coroutine( Fn && fn) :
0101     push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
0102 }
0103 
0104 template< typename T >
0105 template< typename StackAllocator, typename Fn >
0106 push_coroutine< T & >::push_coroutine( StackAllocator && salloc, Fn && fn) :
0107     cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
0108 }
0109 
0110 template< typename T >
0111 push_coroutine< T & >::~push_coroutine() {
0112     if ( nullptr != cb_) {
0113         cb_->deallocate();
0114     }
0115 }
0116 
0117 template< typename T >
0118 push_coroutine< T & >::push_coroutine( push_coroutine && other) noexcept :
0119     cb_{ nullptr } {
0120     std::swap( cb_, other.cb_);
0121 }
0122 
0123 template< typename T >
0124 push_coroutine< T & > &
0125 push_coroutine< T & >::operator()( T & t) {
0126     cb_->resume( t);
0127     return * this;
0128 }
0129 
0130 template< typename T >
0131 push_coroutine< T & >::operator bool() const noexcept {
0132     return nullptr != cb_ && cb_->valid();
0133 }
0134 
0135 template< typename T >
0136 bool
0137 push_coroutine< T & >::operator!() const noexcept {
0138     return nullptr == cb_ || ! cb_->valid();
0139 }
0140 
0141 
0142 // push_coroutine< void >
0143 
0144 inline
0145 push_coroutine< void >::push_coroutine( control_block * cb) noexcept :
0146     cb_{ cb } {
0147 }
0148 
0149 template< typename Fn,
0150           typename
0151 >
0152 push_coroutine< void >::push_coroutine( Fn && fn) :
0153     push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
0154 }
0155 
0156 template< typename StackAllocator, typename Fn >
0157 push_coroutine< void >::push_coroutine( StackAllocator && salloc, Fn && fn) :
0158     cb_{ create_control_block< control_block >( std::forward< StackAllocator >( salloc), std::forward< Fn >( fn) ) } {
0159 }
0160 
0161 inline
0162 push_coroutine< void >::~push_coroutine() {
0163     if ( nullptr != cb_) {
0164         cb_->deallocate();
0165     }
0166 }
0167 
0168 inline
0169 push_coroutine< void >::push_coroutine( push_coroutine && other) noexcept :
0170     cb_{ nullptr } {
0171     std::swap( cb_, other.cb_);
0172 }
0173 
0174 inline
0175 push_coroutine< void > &
0176 push_coroutine< void >::operator()() {
0177     cb_->resume();
0178     return * this;
0179 }
0180 
0181 inline
0182 push_coroutine< void >::operator bool() const noexcept {
0183     return nullptr != cb_ && cb_->valid();
0184 }
0185 
0186 inline
0187 bool
0188 push_coroutine< void >::operator!() const noexcept {
0189     return nullptr == cb_ || ! cb_->valid();
0190 }
0191 
0192 }}}
0193 
0194 #ifdef BOOST_HAS_ABI_HEADERS
0195 #  include BOOST_ABI_SUFFIX
0196 #endif
0197 
0198 #endif // BOOST_COROUTINES2_DETAIL_PUSH_COROUTINE_IPP