Ignore:
Timestamp:
2019-07-01T09:49:54Z (5 years ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
60cb9e1
Parents:
3a29607
Message:

cpp: remove unneeded std:: prefixes and add implementations for future<R&> and future<void>

File:
1 edited

Legend:

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

    r3a29607 rbd6ad4b  
    5454
    5555                future_base(future_base&& rhs) noexcept
    56                     : state_{std::move(rhs.state_)}
     56                    : state_{move(rhs.state_)}
    5757                {
    5858                    rhs.state_ = nullptr;
     
    8080                {
    8181                    release_state_();
    82                     state_ = std::move(rhs.state_);
     82                    state_ = move(rhs.state_);
    8383                    rhs.state_ = nullptr;
    8484                }
     
    162162
    163163            future(future&& rhs) noexcept
    164                 : aux::future_base<R>{std::move(rhs.state_)}
     164                : aux::future_base<R>{move(rhs.state_)}
    165165            { /* DUMMY BODY */ }
    166166
     
    173173            future& operator=(future&& rhs) noexcept
    174174            {
    175                 return aux::future_base<R>::operator=(std::move(rhs));
     175                return aux::future_base<R>::operator=(move(rhs));
    176176            }
    177177
    178178            shared_future<R> share()
    179179            {
    180                 return shared_future<R>(std::move(*this));
     180                return shared_future<R>(move(*this));
    181181            }
    182182
     
    190190                    this->state_->throw_stored_exception();
    191191
     192                return move(this->state_->get());
     193            }
     194    };
     195
     196    template<class R>
     197    class future<R&>: public aux::future_base<R&>
     198    {
     199        public:
     200            future() noexcept
     201                : aux::future_base<R&>{}
     202            { /* DUMMY BODY */ }
     203
     204            future(const future&) = delete;
     205
     206            future(future&& rhs) noexcept
     207                : aux::future_base<R&>{move(rhs.state_)}
     208            { /* DUMMY BODY */ }
     209
     210            future(aux::shared_state<R&>* state)
     211                : aux::future_base<R&>{state}
     212            { /* DUMMY BODY */ }
     213
     214            future& operator=(const future&) = delete;
     215
     216            future& operator=(future&& rhs) noexcept
     217            {
     218                return aux::future_base<R>::operator=(move(rhs));
     219            }
     220
     221            shared_future<R&> share()
     222            {
     223                return shared_future<R&>(move(*this));
     224            }
     225
     226            R& get()
     227            {
     228                assert(this->state_);
     229
     230                this->wait();
     231
     232                if (this->state_->has_exception())
     233                    this->state_->throw_stored_exception();
     234
    192235                return this->state_->get();
    193236            }
    194237    };
    195238
    196     template<class R>
    197     class future<R&>
    198     {
    199         // TODO: Copy & modify once future is done.
    200     };
    201 
    202239    template<>
    203     class future<void>
    204     {
    205         // TODO: Copy & modify once future is done.
     240    class future<void>: public aux::future_base<void>
     241    {
     242        public:
     243            future() noexcept
     244                : aux::future_base<void>{}
     245            { /* DUMMY BODY */ }
     246
     247            future(const future&) = delete;
     248
     249            future(future&& rhs) noexcept
     250                : aux::future_base<void>{move(rhs.state_)}
     251            { /* DUMMY BODY */ }
     252
     253            future(aux::shared_state<void>* state)
     254                : aux::future_base<void>{state}
     255            { /* DUMMY BODY */ }
     256
     257            future& operator=(const future&) = delete;
     258
     259            future& operator=(future&& rhs) noexcept = default;
     260
     261            /* shared_future<void> share() */
     262            /* { */
     263            /*     return shared_future<void>(move(*this)); */
     264            /* } */
     265
     266            void get()
     267            {
     268                assert(this->state_);
     269
     270                this->wait();
     271
     272                if (this->state_->has_exception())
     273                    this->state_->throw_stored_exception();
     274            }
    206275    };
    207276}
Note: See TracChangeset for help on using the changeset viewer.