Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/outcome/success_failure.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* Type sugar for success and failure
0002 (C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (25 commits)
0003 File Created: July 2017
0004 
0005 
0006 Boost Software License - Version 1.0 - August 17th, 2003
0007 
0008 Permission is hereby granted, free of charge, to any person or organization
0009 obtaining a copy of the software and accompanying documentation covered by
0010 this license (the "Software") to use, reproduce, display, distribute,
0011 execute, and transmit the Software, and to prepare derivative works of the
0012 Software, and to permit third-parties to whom the Software is furnished to
0013 do so, all subject to the following:
0014 
0015 The copyright notices in the Software and this entire statement, including
0016 the above license grant, this restriction and the following disclaimer,
0017 must be included in all copies of the Software, in whole or in part, and
0018 all derivative works of the Software, unless such copies or derivative
0019 works are solely in the form of machine-executable object code generated by
0020 a source language processor.
0021 
0022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0024 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
0025 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
0026 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
0027 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0028 DEALINGS IN THE SOFTWARE.
0029 */
0030 
0031 #ifndef BOOST_OUTCOME_SUCCESS_FAILURE_HPP
0032 #define BOOST_OUTCOME_SUCCESS_FAILURE_HPP
0033 
0034 #include "config.hpp"
0035 
0036 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
0037 
0038 /*! AWAITING HUGO JSON CONVERSION TOOL
0039 type definition template <class T> success_type. Potential doc page: `success_type<T>`
0040 */
0041 template <class T> struct BOOST_OUTCOME_NODISCARD success_type
0042 {
0043   using value_type = T;
0044 
0045 private:
0046   value_type _value;
0047   uint16_t _spare_storage{0};
0048 
0049 public:
0050   success_type() = default;
0051   success_type(const success_type &) = default;
0052   success_type(success_type &&) = default;  // NOLINT
0053   success_type &operator=(const success_type &) = default;
0054   success_type &operator=(success_type &&) = default;  // NOLINT
0055   ~success_type() = default;
0056   BOOST_OUTCOME_TEMPLATE(class U)
0057   BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_same<success_type, std::decay_t<U>>::value))
0058   constexpr explicit success_type(U &&v, uint16_t spare_storage = 0)
0059       : _value(static_cast<U &&>(v))  // NOLINT
0060       , _spare_storage(spare_storage)
0061   {
0062   }
0063 
0064   constexpr value_type &value() & { return _value; }
0065   constexpr const value_type &value() const & { return _value; }
0066   constexpr value_type &&value() && { return static_cast<value_type &&>(_value); }
0067   constexpr const value_type &&value() const && { return static_cast<value_type &&>(_value); }
0068 
0069   constexpr uint16_t spare_storage() const { return _spare_storage; }
0070 };
0071 template <> struct BOOST_OUTCOME_NODISCARD success_type<void>
0072 {
0073   using value_type = void;
0074 
0075   constexpr uint16_t spare_storage() const { return 0; }
0076 };
0077 /*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state,
0078 default constructing `T` if necessary.
0079 */
0080 inline constexpr success_type<void> success() noexcept
0081 {
0082   return success_type<void>{};
0083 }
0084 /*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
0085 \effects Copies the successful state supplied into the returned type sugar.
0086 */
0087 BOOST_OUTCOME_TEMPLATE(class T)
0088 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<T>::value))
0089 inline constexpr success_type<std::decay_t<T>> success(const T &v, uint16_t spare_storage = 0)
0090 {
0091   return success_type<std::decay_t<T>>{v, spare_storage};
0092 }
0093 /*! Returns type sugar for implicitly constructing a `basic_result<T>` with a successful state.
0094 \effects Moves the successful state supplied into the returned type sugar.
0095 */
0096 BOOST_OUTCOME_TEMPLATE(class T)
0097 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_move_constructible<T>::value))
0098 inline constexpr success_type<std::decay_t<T>> success(T &&v, uint16_t spare_storage = 0)
0099 {
0100   return success_type<std::decay_t<T>>{static_cast<T &&>(v), spare_storage};
0101 }
0102 
0103 /*! AWAITING HUGO JSON CONVERSION TOOL
0104 type definition template <class EC, class E = void> failure_type. Potential doc page: `failure_type<EC, EP = void>`
0105 */
0106 template <class EC, class E = void> struct BOOST_OUTCOME_NODISCARD failure_type
0107 {
0108   using error_type = EC;
0109   using exception_type = E;
0110 
0111 private:
0112   error_type _error;
0113   exception_type _exception;
0114   bool _have_error{false}, _have_exception{false};
0115   uint16_t _spare_storage{0};
0116 
0117   struct error_init_tag
0118   {
0119   };
0120   struct exception_init_tag
0121   {
0122   };
0123 
0124 public:
0125   failure_type() = default;
0126   failure_type(const failure_type &) = default;
0127   failure_type(failure_type &&) = default;  // NOLINT
0128   failure_type &operator=(const failure_type &) = default;
0129   failure_type &operator=(failure_type &&) = default;  // NOLINT
0130   ~failure_type() = default;
0131   template <class U, class V>
0132   constexpr explicit failure_type(U &&u, V &&v, uint16_t spare_storage = 0)
0133       : _error(static_cast<U &&>(u))
0134       , _exception(static_cast<V &&>(v))
0135       , _have_error(true)
0136       , _have_exception(true)
0137       , _spare_storage(spare_storage)
0138   {
0139   }
0140   template <class U>
0141   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())
0142       : _error(static_cast<U &&>(u))
0143       , _exception()
0144       , _have_error(true)
0145       , _spare_storage(spare_storage)
0146   {
0147   }
0148   template <class U>
0149   constexpr explicit failure_type(in_place_type_t<exception_type> /*unused*/, U &&u, uint16_t spare_storage = 0,
0150                                   exception_init_tag /*unused*/ = exception_init_tag())
0151       : _error()
0152       , _exception(static_cast<U &&>(u))
0153       , _have_exception(true)
0154       , _spare_storage(spare_storage)
0155   {
0156   }
0157 
0158   constexpr bool has_error() const { return _have_error; }
0159   constexpr bool has_exception() const { return _have_exception; }
0160 
0161   constexpr error_type &error() & { return _error; }
0162   constexpr const error_type &error() const & { return _error; }
0163   constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
0164   constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
0165 
0166   constexpr exception_type &exception() & { return _exception; }
0167   constexpr const exception_type &exception() const & { return _exception; }
0168   constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
0169   constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
0170 
0171   constexpr uint16_t spare_storage() const { return _spare_storage; }
0172 };
0173 template <class EC> struct BOOST_OUTCOME_NODISCARD failure_type<EC, void>
0174 {
0175   using error_type = EC;
0176   using exception_type = void;
0177 
0178 private:
0179   error_type _error;
0180   uint16_t _spare_storage{0};
0181 
0182 public:
0183   failure_type() = default;
0184   failure_type(const failure_type &) = default;
0185   failure_type(failure_type &&) = default;  // NOLINT
0186   failure_type &operator=(const failure_type &) = default;
0187   failure_type &operator=(failure_type &&) = default;  // NOLINT
0188   ~failure_type() = default;
0189   BOOST_OUTCOME_TEMPLATE(class U)
0190   BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<U>>::value))
0191   constexpr explicit failure_type(U &&u, uint16_t spare_storage = 0)
0192       : _error(static_cast<U &&>(u))  // NOLINT
0193       , _spare_storage(spare_storage)
0194   {
0195   }
0196 
0197   constexpr error_type &error() & { return _error; }
0198   constexpr const error_type &error() const & { return _error; }
0199   constexpr error_type &&error() && { return static_cast<error_type &&>(_error); }
0200   constexpr const error_type &&error() const && { return static_cast<error_type &&>(_error); }
0201 
0202   constexpr uint16_t spare_storage() const { return _spare_storage; }
0203 };
0204 template <class E> struct BOOST_OUTCOME_NODISCARD failure_type<void, E>
0205 {
0206   using error_type = void;
0207   using exception_type = E;
0208 
0209 private:
0210   exception_type _exception;
0211   uint16_t _spare_storage{0};
0212 
0213 public:
0214   failure_type() = default;
0215   failure_type(const failure_type &) = default;
0216   failure_type(failure_type &&) = default;  // NOLINT
0217   failure_type &operator=(const failure_type &) = default;
0218   failure_type &operator=(failure_type &&) = default;  // NOLINT
0219   ~failure_type() = default;
0220   BOOST_OUTCOME_TEMPLATE(class V)
0221   BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_same<failure_type, std::decay_t<V>>::value))
0222   constexpr explicit failure_type(V &&v, uint16_t spare_storage = 0)
0223       : _exception(static_cast<V &&>(v))  // NOLINT
0224       , _spare_storage(spare_storage)
0225   {
0226   }
0227 
0228   constexpr exception_type &exception() & { return _exception; }
0229   constexpr const exception_type &exception() const & { return _exception; }
0230   constexpr exception_type &&exception() && { return static_cast<exception_type &&>(_exception); }
0231   constexpr const exception_type &&exception() const && { return static_cast<exception_type &&>(_exception); }
0232 
0233   constexpr uint16_t spare_storage() const { return _spare_storage; }
0234 };
0235 /*! AWAITING HUGO JSON CONVERSION TOOL
0236 SIGNATURE NOT RECOGNISED
0237 */
0238 BOOST_OUTCOME_TEMPLATE(class EC)
0239 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<EC>::value))
0240 inline constexpr failure_type<std::decay_t<EC>> failure(const EC &v, uint16_t spare_storage = 0)
0241 {
0242   return failure_type<std::decay_t<EC>>{v, spare_storage};
0243 }
0244 /*! AWAITING HUGO JSON CONVERSION TOOL
0245 SIGNATURE NOT RECOGNISED
0246 */
0247 BOOST_OUTCOME_TEMPLATE(class EC)
0248 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_move_constructible<EC>::value))
0249 inline constexpr failure_type<std::decay_t<EC>> failure(EC &&v, uint16_t spare_storage = 0)
0250 {
0251   return failure_type<std::decay_t<EC>>{static_cast<EC &&>(v), spare_storage};
0252 }
0253 /*! AWAITING HUGO JSON CONVERSION TOOL
0254 SIGNATURE NOT RECOGNISED
0255 */
0256 BOOST_OUTCOME_TEMPLATE(class EC, class E)
0257 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_copy_constructible<E>::value))
0258 inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, const E &w, uint16_t spare_storage = 0)
0259 {
0260   return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, w, spare_storage};
0261 }
0262 /*! AWAITING HUGO JSON CONVERSION TOOL
0263 SIGNATURE NOT RECOGNISED
0264 */
0265 BOOST_OUTCOME_TEMPLATE(class EC, class E)
0266 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<EC>::value &&std::is_move_constructible<E>::value))
0267 inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(const EC &v, E &&w, uint16_t spare_storage = 0)
0268 {
0269   return failure_type<std::decay_t<EC>, std::decay_t<E>>{v, static_cast<E &&>(w), spare_storage};
0270 }
0271 /*! AWAITING HUGO JSON CONVERSION TOOL
0272 SIGNATURE NOT RECOGNISED
0273 */
0274 BOOST_OUTCOME_TEMPLATE(class EC, class E)
0275 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_copy_constructible<E>::value))
0276 inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, const E &w, uint16_t spare_storage = 0)
0277 {
0278   return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), w, spare_storage};
0279 }
0280 /*! AWAITING HUGO JSON CONVERSION TOOL
0281 SIGNATURE NOT RECOGNISED
0282 */
0283 BOOST_OUTCOME_TEMPLATE(class EC, class E)
0284 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_move_constructible<EC>::value &&std::is_move_constructible<E>::value))
0285 inline constexpr failure_type<std::decay_t<EC>, std::decay_t<E>> failure(EC &&v, E &&w, uint16_t spare_storage = 0)
0286 {
0287   return failure_type<std::decay_t<EC>, std::decay_t<E>>{static_cast<EC &&>(v), static_cast<E &&>(w), spare_storage};
0288 }
0289 
0290 namespace detail
0291 {
0292   template <class T> struct is_success_type
0293   {
0294     static constexpr bool value = false;
0295   };
0296   template <class T> struct is_success_type<success_type<T>>
0297   {
0298     static constexpr bool value = true;
0299   };
0300   template <class T> struct is_failure_type
0301   {
0302     static constexpr bool value = false;
0303   };
0304   template <class EC, class E> struct is_failure_type<failure_type<EC, E>>
0305   {
0306     static constexpr bool value = true;
0307   };
0308 }  // namespace detail
0309 
0310 /*! AWAITING HUGO JSON CONVERSION TOOL
0311 SIGNATURE NOT RECOGNISED
0312 */
0313 template <class T> static constexpr bool is_success_type = detail::is_success_type<std::decay_t<T>>::value;
0314 
0315 /*! AWAITING HUGO JSON CONVERSION TOOL
0316 SIGNATURE NOT RECOGNISED
0317 */
0318 template <class T> static constexpr bool is_failure_type = detail::is_failure_type<std::decay_t<T>>::value;
0319 
0320 BOOST_OUTCOME_V2_NAMESPACE_END
0321 
0322 #endif