Ignore:
Timestamp:
2019-07-01T15:42:54Z (5 years ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1621f91
Parents:
a6c3bf3
Message:

cpp: remove redundant specializations similarly to how we did it with shared_future

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/__bits/thread/future.hpp

    ra6c3bf3 r8660ad0  
    171171
    172172    template<class R>
    173     class future: public aux::future_base<R>
     173    class future: public aux::future_base<aux::future_inner_t<R>>
    174174    {
    175175        friend class shared_future<R>;
     
    177177        public:
    178178            future() noexcept
    179                 : aux::future_base<R>{}
     179                : aux::future_base<aux::future_inner_t<R>>{}
    180180            { /* DUMMY BODY */ }
    181181
     
    183183
    184184            future(future&& rhs) noexcept
    185                 : aux::future_base<R>{move(rhs.state_)}
     185                : aux::future_base<aux::future_inner_t<R>>{move(rhs.state_)}
    186186            { /* DUMMY BODY */ }
    187187
    188             future(aux::shared_state<R>* state)
    189                 : aux::future_base<R>{state}
     188            future(aux::shared_state<aux::future_inner_t<R>>* state)
     189                : aux::future_base<aux::future_inner_t<R>>{state}
    190190            { /* DUMMY BODY */ }
    191191
     
    199199            }
    200200
    201             R get()
     201            aux::future_return_t<R> get()
    202202            {
    203203                assert(this->state_);
     
    208208                    this->state_->throw_stored_exception();
    209209
    210                 return move(this->state_->get());
    211             }
    212     };
    213 
    214     template<class R>
    215     class future<R&>: public aux::future_base<R*>
    216     {
    217         friend class shared_future<R&>;
    218 
    219         public:
    220             future() noexcept
    221                 : aux::future_base<R*>{}
    222             { /* DUMMY BODY */ }
    223 
    224             future(const future&) = delete;
    225 
    226             future(future&& rhs) noexcept
    227                 : aux::future_base<R*>{move(rhs.state_)}
    228             { /* DUMMY BODY */ }
    229 
    230             future(aux::shared_state<R*>* state)
    231                 : aux::future_base<R*>{state}
    232             { /* DUMMY BODY */ }
    233 
    234             future& operator=(const future&) = delete;
    235 
    236             future& operator=(future&& rhs) noexcept = default;
    237 
    238             shared_future<R&> share()
    239             {
    240                 return shared_future<R&>{move(*this)};
    241             }
    242 
    243             R& get()
    244             {
    245                 assert(this->state_);
    246 
    247                 this->wait();
    248 
    249                 if (this->state_->has_exception())
    250                     this->state_->throw_stored_exception();
    251 
    252                 assert(this->state_->get());
    253                 return *this->state_->get();
    254             }
    255     };
    256 
    257     template<>
    258     class future<void>: public aux::future_base<void>
    259     {
    260         friend class shared_future<void>;
    261 
    262         public:
    263             future() noexcept
    264                 : aux::future_base<void>{}
    265             { /* DUMMY BODY */ }
    266 
    267             future(const future&) = delete;
    268 
    269             future(future&& rhs) noexcept
    270                 : aux::future_base<void>{move(rhs.state_)}
    271             { /* DUMMY BODY */ }
    272 
    273             future(aux::shared_state<void>* state)
    274                 : aux::future_base<void>{state}
    275             { /* DUMMY BODY */ }
    276 
    277             future& operator=(const future&) = delete;
    278 
    279             future& operator=(future&& rhs) noexcept = default;
    280 
    281             /**
    282              * Note: This is just forward declaration, implementation
    283              *       provided in shared_future.hpp to avoid problems
    284              *       with incomplete types.
    285              */
    286             shared_future<void> share();
    287 
    288             void get()
    289             {
    290                 assert(this->state_);
    291 
    292                 this->wait();
    293 
    294                 if (this->state_->has_exception())
    295                     this->state_->throw_stored_exception();
     210                if constexpr (!is_same_v<R, void>)
     211                {
     212                    if constexpr (is_reference_v<R>)
     213                    {
     214                        assert(this->state_->get());
     215
     216                        return *this->state_->get();
     217                    }
     218                    else
     219                        return this->state_->get();
     220                }
    296221            }
    297222    };
Note: See TracChangeset for help on using the changeset viewer.