123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_STATUS_ERROR_HPP
- #define BOOST_OUTCOME_SYSTEM_ERROR2_STATUS_ERROR_HPP
- #include "status_code.hpp"
- #include <exception>
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
- template <class DomainType> class status_error;
- template <> class status_error<void> : public std::exception
- {
- protected:
-
- status_error() = default;
-
- status_error(const status_error &) = default;
-
- status_error(status_error &&) = default;
-
- status_error &operator=(const status_error &) = default;
-
- status_error &operator=(status_error &&) = default;
-
- ~status_error() override = default;
- virtual const status_code<void> &_do_code() const noexcept = 0;
- public:
-
- using domain_type = void;
-
- using status_code_type = status_code<void>;
- public:
-
- const status_code<void> &code() const noexcept { return _do_code(); }
- };
- template <class DomainType> class status_error : public status_error<void>
- {
- status_code<DomainType> _code;
- typename DomainType::string_ref _msgref;
- virtual const status_code<void> &_do_code() const noexcept override final { return _code; }
- public:
-
- using domain_type = DomainType;
-
- using status_code_type = status_code<DomainType>;
-
- explicit status_error(status_code<DomainType> code)
- : _code(static_cast<status_code<DomainType> &&>(code))
- , _msgref(_code.message())
- {
- }
-
- virtual const char *what() const noexcept override { return _msgref.c_str(); }
-
- const status_code_type &code() const & { return _code; }
-
- status_code_type &code() & { return _code; }
-
- const status_code_type &&code() const && { return _code; }
-
- status_code_type &&code() && { return _code; }
- };
- template <class ErasedType> class status_error<detail::erased<ErasedType>> : public status_error<void>
- {
- status_code<detail::erased<ErasedType>> _code;
- typename status_code_domain::string_ref _msgref;
- virtual const status_code<detail::erased<ErasedType>> &_do_code() const noexcept override final { return _code; }
- public:
-
- using domain_type = void;
-
- using status_code_type = status_code<detail::erased<ErasedType>>;
-
- explicit status_error(status_code<detail::erased<ErasedType>> code)
- : _code(static_cast<status_code<detail::erased<ErasedType>> &&>(code))
- , _msgref(_code.message())
- {
- }
-
- virtual const char *what() const noexcept override { return _msgref.c_str(); }
-
- const status_code_type &code() const & { return _code; }
-
- status_code_type &code() & { return _code; }
-
- const status_code_type &&code() const && { return _code; }
-
- status_code_type &&code() && { return _code; }
- };
- BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
- #endif
|