Changeset 4727aacd in mainline


Ignore:
Timestamp:
2018-07-05T21:41:24Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f2ba4c79
Parents:
4dfac1e
git-author:
Dzejrou <dzejrou@…> (2018-05-14 19:28:19)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:24)
Message:

cpp: added WIP version of <future>

Location:
uspace/lib/cpp
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/Makefile

    r4dfac1e r4727aacd  
    4040        src/condition_variable.cpp \
    4141        src/exception.cpp \
     42        src/future.cpp \
    4243        src/iomanip.cpp \
    4344        src/ios.cpp \
  • uspace/lib/cpp/include/impl/future.hpp

    r4dfac1e r4727aacd  
    3030#define LIBCPP_FUTURE
    3131
    32 #error "<future> is not implemented"
     32#include <memory>
     33#include <system_error>
     34#include <type_traits>
     35
     36namespace std
     37{
     38    /**
     39     * 30.6, futures:
     40     */
     41
     42    enum class future_errc
     43    { // The 5001 start is to not collide with system_error's codes.
     44        broken_promise = 5001,
     45        future_already_retrieved,
     46        promise_already_satisfied,
     47        no_state
     48    };
     49
     50    enum class launch
     51    {
     52        async,
     53        deferred
     54    };
     55
     56    enum class future_status
     57    {
     58        ready,
     59        timeout,
     60        deferred
     61    };
     62
     63    /**
     64     * 30.6.2, error handling:
     65     */
     66
     67    template<>
     68    struct is_error_code_enum<future_errc>: true_type
     69    { /* DUMMY BODY */ };
     70
     71    error_code make_error_code(future_errc) noexcept;
     72    error_condition make_error_condition(future_errc) noexcept;
     73
     74    const error_category& future_category() noexcept;
     75
     76    /**
     77     * 30.6.3, class future_error:
     78     */
     79
     80    class future_error: public logic_error
     81    {
     82        public:
     83            future_error(error_code ec);
     84
     85            const error_code& code() const noexcept;
     86
     87        private:
     88            error_code code_;
     89    };
     90
     91    /**
     92     * 30.6.4, shared state:
     93     */
     94
     95    template<class R>
     96    class promise
     97    {
     98    };
     99
     100    template<class R>
     101    class promise<R&>
     102    {
     103    };
     104
     105    template<>
     106    class promise<void>
     107    {
     108    };
     109
     110    template<class R>
     111    void swap(promise<R>& lhs, promise<R>& rhs) noexcept
     112    {
     113        lhs.swap(rhs);
     114    }
     115
     116    template<class R, class Alloc>
     117    struct uses_allocator<promise<R>, Alloc>: true_type
     118    { /* DUMMY BODY */ };
     119
     120    template<class R>
     121    class future
     122    {
     123    };
     124
     125    template<class R>
     126    class future<R&>
     127    {
     128    };
     129
     130    template<>
     131    class future<void>
     132    {
     133    };
     134
     135    template<class R>
     136    class shared_future
     137    {
     138    };
     139
     140    template<class R>
     141    class shared_future<R&>
     142    {
     143    };
     144
     145    template<>
     146    class shared_future<void>
     147    {
     148    };
     149
     150    template<class>
     151    class packaged_task; // undefined
     152
     153    template<class R, class... Args>
     154    class packaged_task<R(Args...)>
     155    {
     156    };
     157
     158    template<class R, class... Args>
     159    void swap(packaged_task<R(Args...)>& lhs, packaged_task<R(Args...)>& rhs) noexcept
     160    {
     161        lhs.swap(rhs);
     162    };
     163
     164    template<class R, class Alloc>
     165    struct uses_allocator<packaged_task<R>, Alloc>: true_type
     166    { /* DUMMY BODY */ };
     167
     168    template<class F, class... Args>
     169    future<result_of_t<decay_t<F>(decay_t<Args>...)>>
     170    async(F&& f, Args&&... args)
     171    {
     172        // TODO: implement
     173    }
     174
     175    template<class F, class... Args>
     176    future<result_of_t<decay_t<F>(decay_t<Args>...)>>
     177    async(launch, F&& f, Args&&... args)
     178    {
     179        // TODO: implement
     180    }
     181}
    33182
    34183#endif
Note: See TracChangeset for help on using the changeset viewer.