diff options
Diffstat (limited to 'boost/fiber/future/detail/task_object.hpp')
-rw-r--r-- | boost/fiber/future/detail/task_object.hpp | 88 |
1 files changed, 51 insertions, 37 deletions
diff --git a/boost/fiber/future/detail/task_object.hpp b/boost/fiber/future/detail/task_object.hpp index 37bfd3fd11..3a48929a58 100644 --- a/boost/fiber/future/detail/task_object.hpp +++ b/boost/fiber/future/detail/task_object.hpp @@ -9,10 +9,13 @@ #include <exception> #include <memory> +#include <tuple> #include <utility> #include <boost/config.hpp> +#if defined(BOOST_NO_CXX17_STD_APPLY) #include <boost/context/detail/apply.hpp> +#endif #include <boost/fiber/detail/config.hpp> #include <boost/fiber/future/detail/task_base.hpp> @@ -28,43 +31,49 @@ namespace detail { template< typename Fn, typename Allocator, typename R, typename ... Args > class task_object : public task_base< R, Args ... > { private: - typedef task_base< R, Args ... > base_t; + typedef task_base< R, Args ... > base_type; public: typedef typename std::allocator_traits< Allocator >::template rebind_alloc< task_object - > allocator_t; + > allocator_type; - task_object( allocator_t const& alloc, Fn const& fn) : - base_t(), - fn_( fn), - alloc_( alloc) { + task_object( allocator_type const& alloc, Fn const& fn) : + base_type{}, + fn_{ fn }, + alloc_{ alloc } { } - task_object( allocator_t const& alloc, Fn && fn) : - base_t(), - fn_( std::move( fn) ), - alloc_( alloc) { + task_object( allocator_type const& alloc, Fn && fn) : + base_type{}, + fn_{ std::move( fn) }, + alloc_{ alloc } { } void run( Args && ... args) override final { try { this->set_value( +#if defined(BOOST_NO_CXX17_STD_APPLY) boost::context::detail::apply( - fn_, std::make_tuple( std::forward< Args >( args) ... ) ) ); + fn_, std::make_tuple( std::forward< Args >( args) ... ) ) +#else + std::apply( + fn_, std::make_tuple( std::forward< Args >( args) ... ) ) +#endif + ); } catch (...) { this->set_exception( std::current_exception() ); } } - typename base_t::ptr_t reset() override final { - typedef std::allocator_traits< allocator_t > traits_t; + typename base_type::ptr_type reset() override final { + typedef std::allocator_traits< allocator_type > traity_type; - typename traits_t::pointer ptr{ traits_t::allocate( alloc_, 1) }; + typename traity_type::pointer ptr{ traity_type::allocate( alloc_, 1) }; try { - traits_t::construct( alloc_, ptr, alloc_, std::move( fn_) ); + traity_type::construct( alloc_, ptr, alloc_, std::move( fn_) ); } catch (...) { - traits_t::deallocate( alloc_, ptr, 1); + traity_type::deallocate( alloc_, ptr, 1); throw; } return { convert( ptr) }; @@ -77,10 +86,10 @@ protected: private: Fn fn_; - allocator_t alloc_; + allocator_type alloc_; - static void destroy_( allocator_t const& alloc, task_object * p) noexcept { - allocator_t a{ alloc }; + static void destroy_( allocator_type const& alloc, task_object * p) noexcept { + allocator_type a{ alloc }; a.destroy( p); a.deallocate( p, 1); } @@ -89,43 +98,48 @@ private: template< typename Fn, typename Allocator, typename ... Args > class task_object< Fn, Allocator, void, Args ... > : public task_base< void, Args ... > { private: - typedef task_base< void, Args ... > base_t; + typedef task_base< void, Args ... > base_type; public: typedef typename Allocator::template rebind< task_object< Fn, Allocator, void, Args ... > - >::other allocator_t; + >::other allocator_type; - task_object( allocator_t const& alloc, Fn const& fn) : - base_t(), - fn_( fn), - alloc_( alloc) { + task_object( allocator_type const& alloc, Fn const& fn) : + base_type{}, + fn_{ fn }, + alloc_{ alloc } { } - task_object( allocator_t const& alloc, Fn && fn) : - base_t(), - fn_( std::move( fn) ), - alloc_( alloc) { + task_object( allocator_type const& alloc, Fn && fn) : + base_type{}, + fn_{ std::move( fn) }, + alloc_{ alloc } { } void run( Args && ... args) override final { try { +#if defined(BOOST_NO_CXX17_STD_APPLY) boost::context::detail::apply( fn_, std::make_tuple( std::forward< Args >( args) ... ) ); +#else + std::apply( + fn_, std::make_tuple( std::forward< Args >( args) ... ) ); +#endif this->set_value(); } catch (...) { this->set_exception( std::current_exception() ); } } - typename base_t::ptr_t reset() override final { - typedef std::allocator_traits< allocator_t > traits_t; + typename base_type::ptr_type reset() override final { + typedef std::allocator_traits< allocator_type > traity_type; - typename traits_t::pointer ptr{ traits_t::allocate( alloc_, 1) }; + typename traity_type::pointer ptr{ traity_type::allocate( alloc_, 1) }; try { - traits_t::construct( alloc_, ptr, alloc_, std::move( fn_) ); + traity_type::construct( alloc_, ptr, alloc_, std::move( fn_) ); } catch (...) { - traits_t::deallocate( alloc_, ptr, 1); + traity_type::deallocate( alloc_, ptr, 1); throw; } return { convert( ptr) }; @@ -138,10 +152,10 @@ protected: private: Fn fn_; - allocator_t alloc_; + allocator_type alloc_; - static void destroy_( allocator_t const& alloc, task_object * p) noexcept { - allocator_t a{ alloc }; + static void destroy_( allocator_type const& alloc, task_object * p) noexcept { + allocator_type a{ alloc }; a.destroy( p); a.deallocate( p, 1); } |