From a390cc2fbd8eed9464e533472851b6cb15acc1a9 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Wed, 11 Feb 2015 19:57:45 +0100 Subject: [PATCH] use C++14 feature lambda capture expressions --- doc/overview.qbk | 2 +- .../coroutine2/detail/pull_control_block.hpp | 8 +-- .../coroutine2/detail/pull_control_block.ipp | 19 +++---- .../coroutine2/detail/pull_coroutine.ipp | 7 +-- .../coroutine2/detail/push_control_block.hpp | 8 +-- .../coroutine2/detail/push_control_block.ipp | 19 +++---- .../coroutine2/detail/push_coroutine.ipp | 7 +-- include/boost/coroutine2/detail/rref.hpp | 57 ------------------- 8 files changed, 31 insertions(+), 96 deletions(-) delete mode 100644 include/boost/coroutine2/detail/rref.hpp diff --git a/doc/overview.qbk b/doc/overview.qbk index e4ed9d7..3057292 100644 --- a/doc/overview.qbk +++ b/doc/overview.qbk @@ -31,6 +31,6 @@ which includes all the other headers in turn. All functions and classes are contained in the namespace __coro_ns__. -[note __boost_coroutine__ is C++11-only!] +[note __boost_coroutine__ is C++14-only!] [endsect] diff --git a/include/boost/coroutine2/detail/pull_control_block.hpp b/include/boost/coroutine2/detail/pull_control_block.hpp index 0c1d074..f8266d2 100644 --- a/include/boost/coroutine2/detail/pull_control_block.hpp +++ b/include/boost/coroutine2/detail/pull_control_block.hpp @@ -12,8 +12,6 @@ #include #include -#include - #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX #endif @@ -32,7 +30,7 @@ struct pull_coroutine< T >::control_block { std::exception_ptr except; template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, rref< Fn >, bool); + control_block( context::preallocated, StackAllocator, Fn &&, bool); explicit control_block( typename push_coroutine< T >::control_block *); @@ -56,7 +54,7 @@ struct pull_coroutine< T & >::control_block { std::exception_ptr except; template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, rref< Fn >, bool); + control_block( context::preallocated, StackAllocator, Fn &&, bool); explicit control_block( typename push_coroutine< T & >::control_block *); @@ -79,7 +77,7 @@ struct pull_coroutine< void >::control_block { std::exception_ptr except; template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, rref< Fn >, bool); + control_block( context::preallocated, StackAllocator, Fn &&, bool); explicit control_block( push_coroutine< void >::control_block *); diff --git a/include/boost/coroutine2/detail/pull_control_block.ipp b/include/boost/coroutine2/detail/pull_control_block.ipp index fcb7f18..2620d93 100644 --- a/include/boost/coroutine2/detail/pull_control_block.ipp +++ b/include/boost/coroutine2/detail/pull_control_block.ipp @@ -16,7 +16,6 @@ #include #include -#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -32,18 +31,18 @@ namespace detail { template< typename T > template< typename StackAllocator, typename Fn > pull_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - rref< Fn > rr, bool preserve_fpu_) : + Fn && fn_, bool preserve_fpu_) : other( nullptr), caller( boost::context::execution_context::current() ), callee( palloc, salloc, - [=] () mutable { + [=,fn=std::forward< Fn >( fn_)] () mutable { try { // create synthesized push_coroutine< T > typename push_coroutine< T >::control_block synthesized_cb( this); push_coroutine< T > synthesized( & synthesized_cb); other = & synthesized_cb; // call coroutine-fn with synthesized push_coroutine as argument - rr( synthesized); + fn( synthesized); } catch ( forced_unwind const&) { // do nothing for unwinding exception } catch (...) { @@ -107,18 +106,18 @@ pull_coroutine< T >::control_block::valid() const noexcept { template< typename T > template< typename StackAllocator, typename Fn > pull_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - rref< Fn > rr, bool preserve_fpu_) : + Fn && fn_, bool preserve_fpu_) : other( nullptr), caller( boost::context::execution_context::current() ), callee( palloc, salloc, - [=] () mutable { + [=,fn=std::forward< Fn >( fn_)] () mutable { try { // create synthesized push_coroutine< T > typename push_coroutine< T & >::control_block synthesized_cb( this); push_coroutine< T & > synthesized( & synthesized_cb); other = & synthesized_cb; // call coroutine-fn with synthesized push_coroutine as argument - rr( synthesized); + fn( synthesized); } catch ( forced_unwind const&) { // do nothing for unwinding exception } catch (...) { @@ -181,18 +180,18 @@ pull_coroutine< T & >::control_block::valid() const noexcept { template< typename StackAllocator, typename Fn > pull_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - rref< Fn > rr, bool preserve_fpu_) : + Fn && fn_, bool preserve_fpu_) : other( nullptr), caller( boost::context::execution_context::current() ), callee( palloc, salloc, - [=] () mutable { + [=,fn=std::forward< Fn >( fn_)] () mutable { try { // create synthesized push_coroutine< T > typename push_coroutine< void >::control_block synthesized_cb( this); push_coroutine< void > synthesized( & synthesized_cb); other = & synthesized_cb; // call coroutine-fn with synthesized push_coroutine as argument - rr( synthesized); + fn( synthesized); } catch ( forced_unwind const&) { // do nothing for unwinding exception } catch (...) { diff --git a/include/boost/coroutine2/detail/pull_coroutine.ipp b/include/boost/coroutine2/detail/pull_coroutine.ipp index 551c7df..674cf40 100644 --- a/include/boost/coroutine2/detail/pull_coroutine.ipp +++ b/include/boost/coroutine2/detail/pull_coroutine.ipp @@ -17,7 +17,6 @@ #include #include -#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -55,7 +54,7 @@ pull_coroutine< T >::pull_coroutine( StackAllocator salloc, Fn && fn, bool prese void * sp = static_cast< char * >( sctx.sp) - sizeof( control_block); std::size_t size = sctx.size - sizeof( control_block); cb_ = new ( sp) control_block( context::preallocated( sp, size, sctx), - salloc, rref< Fn >( std::forward< Fn >( fn) ), preserve_fpu); + salloc, std::forward< Fn >( fn), preserve_fpu); } template< typename T > @@ -123,7 +122,7 @@ pull_coroutine< T & >::pull_coroutine( StackAllocator salloc, Fn && fn, bool pre void * sp = static_cast< char * >( sctx.sp) - sizeof( control_block); std::size_t size = sctx.size - sizeof( control_block); cb_ = new ( sp) control_block( context::preallocated( sp, size, sctx), - salloc, rref< Fn >( std::forward< Fn >( fn) ), preserve_fpu); + salloc, std::forward< Fn >( fn), preserve_fpu); } template< typename T > @@ -183,7 +182,7 @@ pull_coroutine< void >::pull_coroutine( StackAllocator salloc, Fn && fn, bool pr void * sp = static_cast< char * >( sctx.sp) - sizeof( control_block); std::size_t size = sctx.size - sizeof( control_block); cb_ = new ( sp) control_block( context::preallocated( sp, size, sctx), - salloc, rref< Fn >( std::forward< Fn >( fn) ), preserve_fpu); + salloc, std::forward< Fn >( fn), preserve_fpu); } inline diff --git a/include/boost/coroutine2/detail/push_control_block.hpp b/include/boost/coroutine2/detail/push_control_block.hpp index bc21552..ab0086a 100644 --- a/include/boost/coroutine2/detail/push_control_block.hpp +++ b/include/boost/coroutine2/detail/push_control_block.hpp @@ -12,8 +12,6 @@ #include #include -#include - #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX #endif @@ -33,7 +31,7 @@ struct push_coroutine< T >::control_block { T * t; template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, rref< Fn >, bool); + control_block( context::preallocated, StackAllocator, Fn &&, bool); explicit control_block( typename pull_coroutine< T >::control_block *); @@ -60,7 +58,7 @@ struct push_coroutine< T & >::control_block { T * t; template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, rref< Fn >, bool); + control_block( context::preallocated, StackAllocator, Fn &&, bool); explicit control_block( typename pull_coroutine< T & >::control_block *); @@ -83,7 +81,7 @@ struct push_coroutine< void >::control_block { std::exception_ptr except; template< typename StackAllocator, typename Fn > - control_block( context::preallocated, StackAllocator, rref< Fn >, bool); + control_block( context::preallocated, StackAllocator, Fn &&, bool); explicit control_block( pull_coroutine< void >::control_block *); diff --git a/include/boost/coroutine2/detail/push_control_block.ipp b/include/boost/coroutine2/detail/push_control_block.ipp index 47f0b38..317723a 100644 --- a/include/boost/coroutine2/detail/push_control_block.ipp +++ b/include/boost/coroutine2/detail/push_control_block.ipp @@ -17,7 +17,6 @@ #include #include -#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -33,18 +32,18 @@ namespace detail { template< typename T > template< typename StackAllocator, typename Fn > push_coroutine< T >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - rref< Fn > rr, bool preserve_fpu_) : + Fn && fn_, bool preserve_fpu_) : other( nullptr), caller( boost::context::execution_context::current() ), callee( palloc, salloc, - [=] () mutable { + [=,fn=std::forward< Fn >( fn_)] () mutable { try { // create synthesized pull_coroutine< T > typename pull_coroutine< T >::control_block synthesized_cb( this); pull_coroutine< T > synthesized( & synthesized_cb); other = & synthesized_cb; // call coroutine-fn with synthesized pull_coroutine as argument - rr( synthesized); + fn( synthesized); } catch ( forced_unwind const&) { // do nothing for unwinding exception } catch (...) { @@ -132,18 +131,18 @@ push_coroutine< T >::control_block::valid() const noexcept { template< typename T > template< typename StackAllocator, typename Fn > push_coroutine< T & >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, - rref< Fn > rr, bool preserve_fpu_) : + Fn && fn_, bool preserve_fpu_) : other( nullptr), caller( boost::context::execution_context::current() ), callee( palloc, salloc, - [=] () mutable { + [=,fn=std::forward< Fn >( fn_)] () mutable { try { // create synthesized pull_coroutine< T > typename pull_coroutine< T & >::control_block synthesized_cb( this); pull_coroutine< T & > synthesized( & synthesized_cb); other = & synthesized_cb; // call coroutine-fn with synthesized pull_coroutine as argument - rr( synthesized); + fn( synthesized); } catch ( forced_unwind const&) { // do nothing for unwinding exception } catch (...) { @@ -208,18 +207,18 @@ push_coroutine< T & >::control_block::valid() const noexcept { // push_coroutine< void > template< typename StackAllocator, typename Fn > -push_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, rref< Fn > rr, bool preserve_fpu_) : +push_coroutine< void >::control_block::control_block( context::preallocated palloc, StackAllocator salloc, Fn && fn_, bool preserve_fpu_) : other( nullptr), caller( boost::context::execution_context::current() ), callee( palloc, salloc, - [=] () mutable { + [=,fn=std::forward< Fn >( fn_)] () mutable { try { // create synthesized pull_coroutine< T > typename pull_coroutine< void >::control_block synthesized_cb( this); pull_coroutine< void > synthesized( & synthesized_cb); other = & synthesized_cb; // call coroutine-fn with synthesized pull_coroutine as argument - rr( synthesized); + fn( synthesized); } catch ( forced_unwind const&) { // do nothing for unwinding exception } catch (...) { diff --git a/include/boost/coroutine2/detail/push_coroutine.ipp b/include/boost/coroutine2/detail/push_coroutine.ipp index 6613b97..d4de081 100644 --- a/include/boost/coroutine2/detail/push_coroutine.ipp +++ b/include/boost/coroutine2/detail/push_coroutine.ipp @@ -16,7 +16,6 @@ #include #include -#include #include #ifdef BOOST_HAS_ABI_HEADERS @@ -48,7 +47,7 @@ push_coroutine< T >::push_coroutine( StackAllocator salloc, Fn && fn, bool prese void * sp = static_cast< char * >( sctx.sp) - sizeof( control_block); std::size_t size = sctx.size - sizeof( control_block); cb_= new ( sp) control_block( context::preallocated( sp, size, sctx), - salloc, rref< Fn >( std::forward< Fn >( fn) ), preserve_fpu); + salloc, std::forward< Fn >( fn), preserve_fpu); } template< typename T > @@ -111,7 +110,7 @@ push_coroutine< T & >::push_coroutine( StackAllocator salloc, Fn && fn, bool pre void * sp = static_cast< char * >( sctx.sp) - sizeof( control_block); std::size_t size = sctx.size - sizeof( control_block); cb_ = new ( sp) control_block( context::preallocated( sp, size, sctx), - salloc, rref< Fn >( std::forward< Fn >( fn) ), preserve_fpu); + salloc, std::forward< Fn >( fn), preserve_fpu); } template< typename T > @@ -165,7 +164,7 @@ push_coroutine< void >::push_coroutine( StackAllocator salloc, Fn && fn, bool pr void * sp = static_cast< char * >( sctx.sp) - sizeof( control_block); std::size_t size = sctx.size - sizeof( control_block); cb_ = new ( sp) control_block( context::preallocated( sp, size, sctx), - salloc, rref< Fn >( std::forward< Fn >( fn) ), preserve_fpu); + salloc, std::forward< Fn >( fn), preserve_fpu); } inline diff --git a/include/boost/coroutine2/detail/rref.hpp b/include/boost/coroutine2/detail/rref.hpp deleted file mode 100644 index fd327c3..0000000 --- a/include/boost/coroutine2/detail/rref.hpp +++ /dev/null @@ -1,57 +0,0 @@ - -// Copyright Oliver Kowalke 2013. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_COROUTINES2_DETAIL_RREF_H -#define BOOST_COROUTINES2_DETAIL_RREF_H - -#include - -#include - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost { -namespace coroutines2 { -namespace detail { - -// helper class for capture move-only objects -// generalized lambda captures are supported by C++14 -template< typename Fn > -class rref { -public: - rref( Fn && fn) : - fn_( std::forward< Fn >( fn) ) { - } - - rref( rref & other) : - fn_( std::forward< Fn >( other.fn_) ) { - } - - rref( rref && other) : - fn_( std::forward< Fn >( other.fn_) ) { - } - - rref( rref const& other) = delete; - rref & operator=( rref const& other) = delete; - - template< typename S > - void operator()( S & s) { - return fn_( s); - } - -private: - Fn fn_; -}; - -}}} - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif - -#endif // BOOST_COROUTINES2_DETAIL_RREF_H