123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_ERRORED_STATUS_CODE_HPP
- #define BOOST_OUTCOME_SYSTEM_ERROR2_ERRORED_STATUS_CODE_HPP
- #include "quick_status_code_from_enum.hpp"
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
- template <class DomainType> class errored_status_code : public status_code<DomainType>
- {
- using _base = status_code<DomainType>;
- using _base::clear;
- using _base::success;
- void _check()
- {
- if(_base::success())
- {
- std::terminate();
- }
- }
- public:
-
- using typename _base::domain_type;
-
- using typename _base::value_type;
-
- using typename _base::string_ref;
-
- errored_status_code() = default;
-
- errored_status_code(const errored_status_code &) = default;
-
- errored_status_code(errored_status_code &&) = default;
-
- errored_status_code &operator=(const errored_status_code &) = default;
-
- errored_status_code &operator=(errored_status_code &&) = default;
- ~errored_status_code() = default;
-
- explicit errored_status_code(const _base &o) noexcept(std::is_nothrow_copy_constructible<_base>::value)
- : _base(o)
- {
- _check();
- }
-
- explicit errored_status_code(_base &&o) noexcept(std::is_nothrow_move_constructible<_base>::value)
- : _base(static_cast<_base &&>(o))
- {
- _check();
- }
-
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(
- class T, class... Args,
- class MakeStatusCodeResult =
- typename detail::safe_get_make_status_code_result<T, Args...>::type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, errored_status_code>::value
- && !std::is_same<typename std::decay<T>::type, in_place_t>::value
- && is_status_code<MakeStatusCodeResult>::value
- && std::is_constructible<errored_status_code, MakeStatusCodeResult>::value))
- errored_status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...)))
- : errored_status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
- {
- _check();
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class Enum,
- class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(std::is_constructible<errored_status_code, QuickStatusCodeType>::value))
- errored_status_code(Enum &&v) noexcept(std::is_nothrow_constructible<errored_status_code, QuickStatusCodeType>::value)
- : errored_status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
- {
- _check();
- }
-
- template <class... Args>
- explicit errored_status_code(in_place_t _, Args &&...args) noexcept(std::is_nothrow_constructible<value_type, Args &&...>::value)
- : _base(_, static_cast<Args &&>(args)...)
- {
- _check();
- }
-
- template <class T, class... Args>
- explicit errored_status_code(in_place_t _, std::initializer_list<T> il,
- Args &&...args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<T>, Args &&...>::value)
- : _base(_, il, static_cast<Args &&>(args)...)
- {
- _check();
- }
-
- explicit errored_status_code(const value_type &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
- : _base(v)
- {
- _check();
- }
-
- explicit errored_status_code(value_type &&v) noexcept(std::is_nothrow_move_constructible<value_type>::value)
- : _base(static_cast<value_type &&>(v))
- {
- _check();
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class ErasedType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<domain_type, detail::erased<ErasedType>>::value))
- explicit errored_status_code(const status_code<detail::erased<ErasedType>> &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
- : errored_status_code(detail::erasure_cast<value_type>(v.value()))
- {
- assert(v.domain() == this->domain());
- _check();
- }
-
- constexpr bool success() const noexcept { return false; }
-
- constexpr const value_type &value() const & noexcept { return this->_value; }
- };
- namespace traits
- {
- template <class DomainType> struct is_move_bitcopying<errored_status_code<DomainType>>
- {
- static constexpr bool value = is_move_bitcopying<typename DomainType::value_type>::value;
- };
- }
- template <class ErasedType> class errored_status_code<detail::erased<ErasedType>> : public status_code<detail::erased<ErasedType>>
- {
- using _base = status_code<detail::erased<ErasedType>>;
- using _base::success;
- void _check()
- {
- if(_base::success())
- {
- std::terminate();
- }
- }
- public:
- using domain_type = typename _base::domain_type;
- using value_type = typename _base::value_type;
- using string_ref = typename _base::string_ref;
-
- errored_status_code() = default;
-
- errored_status_code(const errored_status_code &) = default;
-
- errored_status_code(errored_status_code &&) = default;
-
- errored_status_code &operator=(const errored_status_code &) = default;
-
- errored_status_code &operator=(errored_status_code &&) = default;
- ~errored_status_code() = default;
-
- explicit errored_status_code(const _base &o) noexcept(std::is_nothrow_copy_constructible<_base>::value)
- : _base(o)
- {
- _check();
- }
-
- explicit errored_status_code(_base &&o) noexcept(std::is_nothrow_move_constructible<_base>::value)
- : _base(static_cast<_base &&>(o))
- {
- _check();
- }
-
-
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
- BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
- errored_status_code(const status_code<DomainType> &v) noexcept
- : _base(v)
- {
- _check();
- }
-
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
- BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
- errored_status_code(const errored_status_code<DomainType> &v) noexcept
- : _base(static_cast<const status_code<DomainType> &>(v))
- {
- _check();
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
- errored_status_code(status_code<DomainType> &&v) noexcept
- : _base(static_cast<status_code<DomainType> &&>(v))
- {
- _check();
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
- errored_status_code(errored_status_code<DomainType> &&v) noexcept
- : _base(static_cast<status_code<DomainType> &&>(v))
- {
- _check();
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(
- class T, class... Args,
- class MakeStatusCodeResult =
- typename detail::safe_get_make_status_code_result<T, Args...>::type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, errored_status_code>::value
- && !std::is_same<typename std::decay<T>::type, value_type>::value
- && is_status_code<MakeStatusCodeResult>::value
- && std::is_constructible<errored_status_code, MakeStatusCodeResult>::value))
- errored_status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...)))
- : errored_status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
- {
- _check();
- }
-
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class Enum,
- class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(std::is_constructible<errored_status_code, QuickStatusCodeType>::value))
- errored_status_code(Enum &&v) noexcept(std::is_nothrow_constructible<errored_status_code, QuickStatusCodeType>::value)
- : errored_status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
- {
- _check();
- }
- #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
-
-
- explicit errored_status_code(in_place_t _, const status_code<void> &v)
- : _base(_, v)
- {
- _check();
- }
- #endif
-
- constexpr bool success() const noexcept { return false; }
-
- constexpr value_type value() const noexcept { return this->_value; }
- };
- template <class ErasedType> using erased_errored_status_code = errored_status_code<detail::erased<ErasedType>>;
- namespace traits
- {
- template <class ErasedType> struct is_move_bitcopying<errored_status_code<detail::erased<ErasedType>>>
- {
- static constexpr bool value = true;
- };
- }
- template <class DomainType1, class DomainType2>
- inline bool operator==(const errored_status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
- {
- return a.equivalent(static_cast<const status_code<DomainType2> &>(b));
- }
- template <class DomainType1, class DomainType2> inline bool operator==(const status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
- {
- return a.equivalent(static_cast<const status_code<DomainType2> &>(b));
- }
- template <class DomainType1, class DomainType2> inline bool operator==(const errored_status_code<DomainType1> &a, const status_code<DomainType2> &b) noexcept
- {
- return static_cast<const status_code<DomainType1> &>(a).equivalent(b);
- }
- template <class DomainType1, class DomainType2>
- inline bool operator!=(const errored_status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
- {
- return !a.equivalent(static_cast<const status_code<DomainType2> &>(b));
- }
- template <class DomainType1, class DomainType2> inline bool operator!=(const status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
- {
- return !a.equivalent(static_cast<const status_code<DomainType2> &>(b));
- }
- template <class DomainType1, class DomainType2> inline bool operator!=(const errored_status_code<DomainType1> &a, const status_code<DomainType2> &b) noexcept
- {
- return !static_cast<const status_code<DomainType1> &>(a).equivalent(b);
- }
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType1, class T,
- class MakeStatusCodeResult =
- typename detail::safe_get_make_status_code_result<const T &>::type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value))
- inline bool operator==(const errored_status_code<DomainType1> &a, const T &b)
- {
- return a.equivalent(make_status_code(b));
- }
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class T, class DomainType1,
- class MakeStatusCodeResult =
- typename detail::safe_get_make_status_code_result<const T &>::type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value))
- inline bool operator==(const T &a, const errored_status_code<DomainType1> &b)
- {
- return b.equivalent(make_status_code(a));
- }
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType1, class T,
- class MakeStatusCodeResult =
- typename detail::safe_get_make_status_code_result<const T &>::type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value))
- inline bool operator!=(const errored_status_code<DomainType1> &a, const T &b)
- {
- return !a.equivalent(make_status_code(b));
- }
- BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class T, class DomainType1,
- class MakeStatusCodeResult =
- typename detail::safe_get_make_status_code_result<const T &>::type)
- BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value))
- inline bool operator!=(const T &a, const errored_status_code<DomainType1> &b)
- {
- return !b.equivalent(make_status_code(a));
- }
- template <class DomainType1, class T, //
- class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type
- >
- inline bool operator==(const errored_status_code<DomainType1> &a, const T &b)
- {
- return a.equivalent(QuickStatusCodeType(b));
- }
- template <class T, class DomainType1, //
- class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type
- >
- inline bool operator==(const T &a, const errored_status_code<DomainType1> &b)
- {
- return b.equivalent(QuickStatusCodeType(a));
- }
- template <class DomainType1, class T, //
- class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type
- >
- inline bool operator!=(const errored_status_code<DomainType1> &a, const T &b)
- {
- return !a.equivalent(QuickStatusCodeType(b));
- }
- template <class T, class DomainType1, //
- class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type
- >
- inline bool operator!=(const T &a, const errored_status_code<DomainType1> &b)
- {
- return !b.equivalent(QuickStatusCodeType(a));
- }
- namespace detail
- {
- template <class T> struct is_errored_status_code
- {
- static constexpr bool value = false;
- };
- template <class T> struct is_errored_status_code<errored_status_code<T>>
- {
- static constexpr bool value = true;
- };
- template <class T> struct is_erased_errored_status_code
- {
- static constexpr bool value = false;
- };
- template <class T> struct is_erased_errored_status_code<errored_status_code<erased<T>>>
- {
- static constexpr bool value = true;
- };
- }
- template <class T> struct is_errored_status_code
- {
- static constexpr bool value =
- detail::is_errored_status_code<typename std::decay<T>::type>::value || detail::is_erased_errored_status_code<typename std::decay<T>::type>::value;
- };
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
- #endif
|