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_PUSH_COROUTINE_IPP
8 #define BOOST_COROUTINES2_DETAIL_PUSH_COROUTINE_IPP
12 #include <boost/assert.hpp>
13 #include <boost/config.hpp>
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>
21 #ifdef BOOST_HAS_ABI_HEADERS
22 # include BOOST_ABI_PREFIX
26 namespace coroutines2 {
29 // push_coroutine< T >
31 template< typename T >
32 push_coroutine< T >::push_coroutine( control_block * cb) noexcept :
36 template< typename T >
37 template< typename Fn,
40 push_coroutine< T >::push_coroutine( Fn && fn) :
41 push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
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) ) } {
50 template< typename T >
51 push_coroutine< T >::~push_coroutine() {
52 if ( nullptr != cb_) {
57 template< typename T >
58 push_coroutine< T >::push_coroutine( push_coroutine && other) noexcept :
60 std::swap( cb_, other.cb_);
63 template< typename T >
65 push_coroutine< T >::operator()( T const& t) {
70 template< typename T >
72 push_coroutine< T >::operator()( T && t) {
73 cb_->resume( std::forward< T >( t) );
77 template< typename T >
78 push_coroutine< T >::operator bool() const noexcept {
79 return nullptr != cb_ && cb_->valid();
82 template< typename T >
84 push_coroutine< T >::operator!() const noexcept {
85 return nullptr == cb_ || ! cb_->valid();
89 // push_coroutine< T & >
91 template< typename T >
92 push_coroutine< T & >::push_coroutine( control_block * cb) noexcept :
96 template< typename T >
97 template< typename Fn,
100 push_coroutine< T & >::push_coroutine( Fn && fn) :
101 push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
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) ) } {
110 template< typename T >
111 push_coroutine< T & >::~push_coroutine() {
112 if ( nullptr != cb_) {
117 template< typename T >
118 push_coroutine< T & >::push_coroutine( push_coroutine && other) noexcept :
120 std::swap( cb_, other.cb_);
123 template< typename T >
124 push_coroutine< T & > &
125 push_coroutine< T & >::operator()( T & t) {
130 template< typename T >
131 push_coroutine< T & >::operator bool() const noexcept {
132 return nullptr != cb_ && cb_->valid();
135 template< typename T >
137 push_coroutine< T & >::operator!() const noexcept {
138 return nullptr == cb_ || ! cb_->valid();
142 // push_coroutine< void >
145 push_coroutine< void >::push_coroutine( control_block * cb) noexcept :
149 template< typename Fn,
152 push_coroutine< void >::push_coroutine( Fn && fn) :
153 push_coroutine{ default_stack(), std::forward< Fn >( fn) } {
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) ) } {
162 push_coroutine< void >::~push_coroutine() {
163 if ( nullptr != cb_) {
169 push_coroutine< void >::push_coroutine( push_coroutine && other) noexcept :
171 std::swap( cb_, other.cb_);
175 push_coroutine< void > &
176 push_coroutine< void >::operator()() {
182 push_coroutine< void >::operator bool() const noexcept {
183 return nullptr != cb_ && cb_->valid();
188 push_coroutine< void >::operator!() const noexcept {
189 return nullptr == cb_ || ! cb_->valid();
194 #ifdef BOOST_HAS_ABI_HEADERS
195 # include BOOST_ABI_SUFFIX
198 #endif // BOOST_COROUTINES2_DETAIL_PUSH_COROUTINE_IPP