diff options
Diffstat (limited to 'boost/fiber/future/future.hpp')
-rw-r--r-- | boost/fiber/future/future.hpp | 233 |
1 files changed, 122 insertions, 111 deletions
diff --git a/boost/fiber/future/future.hpp b/boost/fiber/future/future.hpp index d92820eb58..5d4ad78ab5 100644 --- a/boost/fiber/future/future.hpp +++ b/boost/fiber/future/future.hpp @@ -24,13 +24,13 @@ namespace detail { template< typename R > struct future_base { - typedef typename shared_state< R >::ptr_t ptr_t; + typedef typename shared_state< R >::ptr_type ptr_type; - ptr_t state_{}; + ptr_type state_{}; - future_base() noexcept = default; + future_base() = default; - explicit future_base( ptr_t const& p) noexcept : + explicit future_base( ptr_type const& p) noexcept : state_{ p } { } @@ -46,15 +46,17 @@ struct future_base { } future_base & operator=( future_base const& other) noexcept { - if ( this == & other) return * this; - state_ = other.state_; + if ( this != & other) { + state_ = other.state_; + } return * this; } future_base & operator=( future_base && other) noexcept { - if ( this == & other) return * this; - state_ = other.state_; - other.state_.reset(); + if ( this != & other) { + state_ = other.state_; + other.state_.reset(); + } return * this; } @@ -107,128 +109,131 @@ class packaged_task; template< typename R > class future : private detail::future_base< R > { private: - typedef detail::future_base< R > base_t; + typedef detail::future_base< R > base_type; friend struct detail::promise_base< R >; friend class shared_future< R >; template< typename Signature > friend class packaged_task; - explicit future( typename base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit future( typename base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - future() noexcept = default; + future() = default; future( future const&) = delete; future & operator=( future const&) = delete; future( future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } future & operator=( future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } shared_future< R > share(); R get() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } - typename base_t::ptr_t tmp{}; - tmp.swap( base_t::state_); + typename base_type::ptr_type tmp{}; + tmp.swap( base_type::state_); return std::move( tmp->get() ); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template< typename R > class future< R & > : private detail::future_base< R & > { private: - typedef detail::future_base< R & > base_t; + typedef detail::future_base< R & > base_type; friend struct detail::promise_base< R & >; friend class shared_future< R & >; template< typename Signature > friend class packaged_task; - explicit future( typename base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit future( typename base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - future() noexcept = default; + future() = default; future( future const&) = delete; future & operator=( future const&) = delete; future( future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } future & operator=( future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } shared_future< R & > share(); R & get() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } - typename base_t::ptr_t tmp{}; - tmp.swap( base_t::state_); + typename base_type::ptr_type tmp{}; + tmp.swap( base_type::state_); return tmp->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template<> class future< void > : private detail::future_base< void > { private: - typedef detail::future_base< void > base_t; + typedef detail::future_base< void > base_type; friend struct detail::promise_base< void >; friend class shared_future< void >; template< typename Signature > friend class packaged_task; - explicit future( base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit future( base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - future() noexcept = default; + future() = default; future( future const&) = delete; future & operator=( future const&) = delete; inline future( future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } inline future & operator=( future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } @@ -236,62 +241,64 @@ public: inline void get() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } - base_t::ptr_t tmp{}; - tmp.swap( base_t::state_); + base_type::ptr_type tmp{}; + tmp.swap( base_type::state_); tmp->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template< typename R > class shared_future : private detail::future_base< R > { private: - typedef detail::future_base< R > base_t; + typedef detail::future_base< R > base_type; - explicit shared_future( typename base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit shared_future( typename base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - shared_future() noexcept = default; + shared_future() = default; ~shared_future() = default; shared_future( shared_future const& other) : - base_t{ other } { + base_type{ other } { } shared_future( shared_future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } shared_future( future< R > && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } shared_future & operator=( shared_future const& other) noexcept { - if ( this == & other) return * this; - base_t::operator=( other); + if ( this != & other) { + base_type::operator=( other); + } return * this; } shared_future & operator=( shared_future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } shared_future & operator=( future< R > && other) noexcept { - base_t::operator=( std::move( other) ); + base_type::operator=( std::move( other) ); return * this; } @@ -299,56 +306,58 @@ public: if ( ! valid() ) { throw future_uninitialized{}; } - return base_t::state_->get(); + return base_type::state_->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template< typename R > class shared_future< R & > : private detail::future_base< R & > { private: - typedef detail::future_base< R & > base_t; + typedef detail::future_base< R & > base_type; - explicit shared_future( typename base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit shared_future( typename base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - shared_future() noexcept = default; + shared_future() = default; ~shared_future() = default; shared_future( shared_future const& other) : - base_t{ other } { + base_type{ other } { } shared_future( shared_future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } shared_future( future< R & > && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } shared_future & operator=( shared_future const& other) noexcept { - if ( this == & other) return * this; - base_t::operator=( other); + if ( this != & other) { + base_type::operator=( other); + } return * this; } shared_future & operator=( shared_future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } shared_future & operator=( future< R & > && other) noexcept { - base_t::operator=( std::move( other) ); + base_type::operator=( std::move( other) ); return * this; } @@ -356,62 +365,64 @@ public: if ( ! valid() ) { throw future_uninitialized{}; } - return base_t::state_->get(); + return base_type::state_->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template<> class shared_future< void > : private detail::future_base< void > { private: - typedef detail::future_base< void > base_t; + typedef detail::future_base< void > base_type; - explicit shared_future( base_t::ptr_t const& p) noexcept : - base_t{ p } { + explicit shared_future( base_type::ptr_type const& p) noexcept : + base_type{ p } { } public: - shared_future() noexcept = default; + shared_future() = default; ~shared_future() = default; inline shared_future( shared_future const& other) : - base_t{ other } { + base_type{ other } { } inline shared_future( shared_future && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } inline shared_future( future< void > && other) noexcept : - base_t{ std::move( other) } { + base_type{ std::move( other) } { } inline shared_future & operator=( shared_future const& other) noexcept { - if ( this == & other) return * this; - base_t::operator=( other); + if ( this != & other) { + base_type::operator=( other); + } return * this; } inline shared_future & operator=( shared_future && other) noexcept { - if ( this == & other) return * this; - base_t::operator=( std::move( other) ); + if ( this != & other) { + base_type::operator=( std::move( other) ); + } return * this; } inline shared_future & operator=( future< void > && other) noexcept { - base_t::operator=( std::move( other) ); + base_type::operator=( std::move( other) ); return * this; } @@ -420,21 +431,21 @@ public: if ( ! valid() ) { throw future_uninitialized{}; } - base_t::state_->get(); + base_type::state_->get(); } - using base_t::valid; - using base_t::get_exception_ptr; - using base_t::wait; - using base_t::wait_for; - using base_t::wait_until; + using base_type::valid; + using base_type::get_exception_ptr; + using base_type::wait; + using base_type::wait_for; + using base_type::wait_until; }; template< typename R > shared_future< R > future< R >::share() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } return shared_future< R >{ std::move( * this) }; @@ -443,7 +454,7 @@ future< R >::share() { template< typename R > shared_future< R & > future< R & >::share() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } return shared_future< R & >{ std::move( * this) }; @@ -452,7 +463,7 @@ future< R & >::share() { inline shared_future< void > future< void >::share() { - if ( ! base_t::valid() ) { + if ( ! base_type::valid() ) { throw future_uninitialized{}; } return shared_future< void >{ std::move( * this) }; |