source: mainline/uspace/lib/cpp/include/__bits/thread/future_common.hpp@ 4d68584

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4d68584 was 1621f91, checked in by Jaroslav Jindrak <dzejrou@…>, 6 years ago

cpp: fix return types for future<R>::get and shared_future<R>::get

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2019 Jaroslav Jindrak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef LIBCPP_BITS_THREAD_FUTURE_COMMON
30#define LIBCPP_BITS_THREAD_FUTURE_COMMON
31
32#include <__bits/aux.hpp>
33#include <system_error>
34#include <stdexcept>
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 future_status
51 {
52 ready,
53 timeout,
54 deferred
55 };
56
57 /**
58 * 30.6.2, error handling:
59 */
60
61 template<>
62 struct is_error_code_enum<future_errc>: true_type
63 { /* DUMMY BODY */ };
64
65 error_code make_error_code(future_errc) noexcept;
66 error_condition make_error_condition(future_errc) noexcept;
67
68 const error_category& future_category() noexcept;
69
70 /**
71 * 30.6.3, class future_error:
72 */
73
74 class future_error: public logic_error
75 {
76 public:
77 future_error(error_code ec);
78
79 const error_code& code() const noexcept;
80 const char* what() const noexcept;
81
82 private:
83 error_code code_;
84 };
85
86 namespace aux
87 {
88 /**
89 * Auxilliary metafunctions that let us avoid
90 * specializations in some cases. They represent
91 * the inner stored type and the return type of
92 * the get() member function, respectively.
93 */
94
95 template<class T>
96 struct future_inner: aux::type_is<T>
97 { /* DUMMY BODY */ };
98
99 template<class T>
100 struct future_inner<T&>: aux::type_is<T*>
101 { /* DUMMY BODY */ };
102
103 template<class T>
104 using future_inner_t = typename future_inner<T>::type;
105
106 template<class T>
107 struct future_return: aux::type_is<T>
108 { /* DUMMY BODY */ };
109
110 template<class T>
111 struct future_return<T&>: aux::type_is<T&>
112 { /* DUMMY BODY */ };
113
114 template<class T>
115 using future_return_t = typename future_return<T>::type;
116
117 template<class T>
118 struct future_return_shared: aux::type_is<const T&>
119 { /* DUMMY BODY */ };
120
121 template<class T>
122 struct future_return_shared<T&>: aux::type_is<T&>
123 { /* DUMMY BODY */ };
124
125 template<>
126 struct future_return_shared<void>: aux::type_is<void>
127 { /* DUMMY BODY */ };
128
129 template<class T>
130 using future_return_shared_t = typename future_return_shared<T>::type;
131 }
132}
133
134#endif
Note: See TracBrowser for help on using the repository browser.