Blame view

3rdparty/boost_1_81_0/boost/outcome/success_failure.hpp 12.2 KB
63e88f80   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
  /* Type sugar for success and failure
  (C) 2017-2022 Niall Douglas <http://www.nedproductions.biz/> (25 commits)
  File Created: July 2017
  
  
  Boost Software License - Version 1.0 - August 17th, 2003
  
  Permission is hereby granted, free of charge, to any person or organization
  obtaining a copy of the software and accompanying documentation covered by
  this license (the "Software") to use, reproduce, display, distribute,
  execute, and transmit the Software, and to prepare derivative works of the
  Software, and to permit third-parties to whom the Software is furnished to
  do so, all subject to the following:
  
  The copyright notices in the Software and this entire statement, including
  the above license grant, this restriction and the following disclaimer,
  must be included in all copies of the Software, in whole or in part, and
  all derivative works of the Software, unless such copies or derivative
  works are solely in the form of machine-executable object code generated by
  a source language processor.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
  */
  
  #ifndef BOOST_OUTCOME_SUCCESS_FAILURE_HPP
  #define BOOST_OUTCOME_SUCCESS_FAILURE_HPP
  
  #include "config.hpp"
  
  BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  
  /*! AWAITING HUGO JSON CONVERSION TOOL
  type definition template <class T> success_type. Potential doc page: `success_type<T>`
  */
  template <class T> struct BOOST_OUTCOME_NODISCARD success_type
  {
    using value_type = T;
  
  private:
    value_type _value;
    uint16_t _spare_storage{0};
  
  public:
    success_type() = default;
    success_type(const success_type &) = default;
    success_type(success_type &&) = default;  // NOLINT
    success_type &operator=(const success_type &) = default;
    success_type &operator=(success_type &&) = default;  // NOLINT
    ~success_type() = default;
    BOOST_OUTCOME_TEMPLATE(class U)
    BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_same<success_type, std::decay_t<U>>::value))
    constexpr explicit success_type(U &&v, uint16_t spare_storage = 0)
        : _value(static_cast<U &&>(v))  // NOLINT
        , _spare_storage(spare_storage)
    {
    }
  
    constexpr value_type &value() & { return _value; }
    constexpr const value_type &value() const & { return _value; }
    constexpr value_type &&value() && { return static_cast<value_type &&>(_value); }
    constexpr const value_type &&value() const && { return static_cast<value_type &&>(_value); }
  
    constexpr uint16_t spare_storage() const { return _spare_storage; }
  };
  template <> struct BOOST_OUTCOME_NODISCARD success_type<void>
  {
    using value_type = void;
  
    constexpr uint16_t spare_storage() const { return 0; }
  };
  /*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state,
  default constructing `T` if necessary.
  */
  inline constexpr success_type<void> success() noexcept
  {
    return success_type<void>{};
  }
  /*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
  \effects Copies the successful state supplied into the returned type sugar.
  */
  BOOST_OUTCOME_TEMPLATE(class T)
  BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<T>::value))
  inline constexpr success_type<std::decay_t<T>> success(const T &v, uint16_t spare_storage = 0)
  {
    return success_type<std::decay_t<T>>{v, spare_storage};
  }
  /*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
  \effects Moves the successful state supplied into the returned type sugar.
  */
  BOOST_OUTCOME_TEMPLATE(class T)
  BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_move_constructible<T>::value))
  inline constexpr success_type<std::decay_t<T>> success(T &&v, uint16_t spare_storage = 0)
  {
    return success_type<std::decay_t<T>>{static_cast<T &&>(v), spare_storage};
  }
  
  /*! AWAITING HUGO JSON CONVERSION TOOL
  type definition template <class EC, class E = void> failure_type. Potential doc page: `failure_type<EC, EP = void>`
  */
  template <class EC, class E = void> struct BOOST_OUTCOME_NODISCARD failure_type
  {
    using error_type = EC;
    using exception_type = E;
  
  private:
    error_type _error;
    exception_type _exception;
    bool _have_error{false}, _have_exception{false};
    uint16_t _spare_storage{0};
  
    struct error_init_tag
    {
    };
    struct exception_init_tag
    {
    };
  
  public:
    failure_type() = default;
    failure_type(const failure_type &) = default;
    failure_type(failure_type &&) = default;  // NOLINT
    failure_type &operator=(const failure_type &) = default;
    failure_type &operator=(failure_type &&) = default;  // NOLINT
    ~failure_type() = default;
    template <class U, class V>
    constexpr explicit failure_type(U &&u, V &&v, uint16_t spare_storage = 0)
        : _error(static_cast<U &&>(u))
        , _exception(static_cast<V &&>(v))
        , _have_error(true)
        , _have_exception(true)
        , _spare_storage(spare_storage)
    {
    }
    template <class U>
    constexpr explicit failure_type(in_place_type_t<error_type> /*unused*/, U &&u, uint16_t spare_storage = 0, error_init_tag /*unused*/ = error_init_tag())
        : _error(static_cast<U &&>(u))
        , _exception()
        , _have_error(true)
        , _spare_storage(spare_storage)
    {
    }
    template <class U>
    constexpr explicit failure_type(in_place_type_t<exception_type> /*unused*/, U &&u, uint16_t spare_storage = 0,
                                    exception_init_tag /*unused*/ = exception_init_tag())
        : _error()
        , _exception(static_cast<U &&>(u))
        , _have_exception(true)
        , _spare_storage(spare_storage)
    {
    }
  
    constexpr bool has_error() const { return _have_error; }
    constexpr bool has_exception() const { return _have_exception; }
  
    constexpr error_type &error() & { return _error; }
    constexpr const error_type &error() const & { return _error; }
    constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
    constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
  
    constexpr exception_type &exception() & { return _exception; }
    constexpr const exception_type &exception() const & { return _exception; }
    constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
    constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
  
    constexpr uint16_t spare_storage() const { return _spare_storage; }
  };
  template <class EC> struct BOOST_OUTCOME_NODISCARD failure_type<EC, void>
  {
    using error_type = EC;
    using exception_type = void;
  
  private:
    error_type _error;
    uint16_t _spare_storage{0};
  
  public:
    failure_type() = default;
    failure_type(const failure_type &) = default;
    failure_type(failure_type &&) = default;  // NOLINT
    failure_type &operator=(const failure_type &) = default;
    failure_type &operator=(failure_type &&) = default;  // NOLINT
    ~failure_type() = default;
    BOOST_OUTCOME_TEMPLATE(class U)
    BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<U>>::value))
    constexpr explicit failure_type(U &&u, uint16_t spare_storage = 0)
        : _error(static_cast<U &&>(u))  // NOLINT
        , _spare_storage(spare_storage)
    {
    }
  
    constexpr error_type &error() & { return _error; }
    constexpr const error_type &error() const & { return _error; }
    constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
    constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
  
    constexpr uint16_t spare_storage() const { return _spare_storage; }
  };
  template <class E> struct BOOST_OUTCOME_NODISCARD failure_type<void, E>
  {
    using error_type = void;
    using exception_type = E;
  
  private:
    exception_type _exception;
    uint16_t _spare_storage{0};
  
  public:
    failure_type() = default;
    failure_type(const failure_type &) = default;
    failure_type(failure_type &&) = default;  // NOLINT
    failure_type &operator=(const failure_type &) = default;
    failure_type &operator=(failure_type &&) = default;  // NOLINT
    ~failure_type() = default;
    BOOST_OUTCOME_TEMPLATE(class V)
    BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<V>>::value))
    constexpr explicit failure_type(V &&v, uint16_t spare_storage = 0)
        : _exception(static_cast<V &&>(v))  // NOLINT
        , _spare_storage(spare_storage)
    {
    }
  
    constexpr exception_type &exception() & { return _exception; }
    constexpr const exception_type &exception() const & { return _exception; }
    constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
    constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
  
    constexpr uint16_t spare_storage() const { return _spare_storage; }
  };
  /*! AWAITING HUGO JSON CONVERSION TOOL
  SIGNATURE NOT RECOGNISED
  */
  BOOST_OUTCOME_TEMPLATE(class EC)
  BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<EC>::value))
  inline constexpr failure_type<std::decay_t<EC>> failure(const EC &v, uint16_t spare_storage = 0)
  {
    return failure_type<std::decay_t<EC>>{v, spare_storage};
  }
  /*! AWAITING HUGO JSON CONVERSION TOOL
  SIGNATURE NOT RECOGNISED
  */
  BOOST_OUTCOME_TEMPLATE(class EC)
  BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_move_constructible<EC>::value))
  inline constexpr failure_type<std::decay_t<EC>> failure(EC &&v, uint16_t spare_storage = 0)
  {
    return failure_type<std::decay_t<EC>>{static_cast<EC &&>(v), spare_storage};
  }
  /*! AWAITING HUGO JSON CONVERSION TOOL
  SIGNATURE NOT RECOGNISED
  */
  BOOST_OUTCOME_TEMPLATE(class EC, class E)
  BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_copy_constructible<E>::value))
  inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, const E &w, uint16_t spare_storage = 0)
  {
    return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, w, spare_storage};
  }
  /*! AWAITING HUGO JSON CONVERSION TOOL
  SIGNATURE NOT RECOGNISED
  */
  BOOST_OUTCOME_TEMPLATE(class EC, class E)
  BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_move_constructible<E>::value))
  inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, E &&w, uint16_t spare_storage = 0)
  {
    return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, static_cast<E &&>(w), spare_storage};
  }
  /*! AWAITING HUGO JSON CONVERSION TOOL
  SIGNATURE NOT RECOGNISED
  */
  BOOST_OUTCOME_TEMPLATE(class EC, class E)
  BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_copy_constructible<E>::value))
  inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, const E &w, uint16_t spare_storage = 0)
  {
    return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), w, spare_storage};
  }
  /*! AWAITING HUGO JSON CONVERSION TOOL
  SIGNATURE NOT RECOGNISED
  */
  BOOST_OUTCOME_TEMPLATE(class EC, class E)
  BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_move_constructible<E>::value))
  inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, E &&w, uint16_t spare_storage = 0)
  {
    return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), static_cast<E &&>(w), spare_storage};
  }
  
  namespace detail
  {
    template <class T> struct is_success_type
    {
      static constexpr bool value = false;
    };
    template <class T> struct is_success_type<success_type<T>>
    {
      static constexpr bool value = true;
    };
    template <class T> struct is_failure_type
    {
      static constexpr bool value = false;
    };
    template <class EC, class E> struct is_failure_type<failure_type<EC, E>>
    {
      static constexpr bool value = true;
    };
  }  // namespace detail
  
  /*! AWAITING HUGO JSON CONVERSION TOOL
  SIGNATURE NOT RECOGNISED
  */
  template <class T> static constexpr bool is_success_type = detail::is_success_type<std::decay_t<T>>::value;
  
  /*! AWAITING HUGO JSON CONVERSION TOOL
  SIGNATURE NOT RECOGNISED
  */
  template <class T> static constexpr bool is_failure_type = detail::is_failure_type<std::decay_t<T>>::value;
  
  BOOST_OUTCOME_V2_NAMESPACE_END
  
  #endif