1 /* Proposed SG14 status_code 2 (C) 2018-2020 Niall Douglas <http://www.nedproductions.biz/> (5 commits) 3 File Created: Feb 2018 4 5 6 Boost Software License - Version 1.0 - August 17th, 2003 7 8 Permission is hereby granted, free of charge, to any person or organization 9 obtaining a copy of the software and accompanying documentation covered by 10 this license (the "Software") to use, reproduce, display, distribute, 11 execute, and transmit the Software, and to prepare derivative works of the 12 Software, and to permit third-parties to whom the Software is furnished to 13 do so, all subject to the following: 14 15 The copyright notices in the Software and this entire statement, including 16 the above license grant, this restriction and the following disclaimer, 17 must be included in all copies of the Software, in whole or in part, and 18 all derivative works of the Software, unless such copies or derivative 19 works are solely in the form of machine-executable object code generated by 20 a source language processor. 21 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 25 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 26 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 27 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 DEALINGS IN THE SOFTWARE. 29 */ 30 31 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_STATUS_ERROR_HPP 32 #define BOOST_OUTCOME_SYSTEM_ERROR2_STATUS_ERROR_HPP 33 34 #include "status_code.hpp" 35 36 #include <exception> // for std::exception 37 38 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN 39 40 /*! Exception type representing a thrown status_code 41 */ 42 template <class DomainType> class status_error; 43 44 /*! The erased type edition of status_error. 45 */ 46 template <> class status_error<void> : public std::exception 47 { 48 protected: 49 //! Constructs an instance. Not publicly available. 50 status_error() = default; 51 //! Copy constructor. Not publicly available 52 status_error(const status_error &) = default; 53 //! Move constructor. Not publicly available 54 status_error(status_error &&) = default; 55 //! Copy assignment. Not publicly available 56 status_error &operator=(const status_error &) = default; 57 //! Move assignment. Not publicly available 58 status_error &operator=(status_error &&) = default; 59 //! Destructor. Not publicly available. 60 ~status_error() override = default; 61 62 public: 63 //! The type of the status domain 64 using domain_type = void; 65 //! The type of the status code 66 using status_code_type = status_code<void>; 67 }; 68 69 /*! Exception type representing a thrown status_code 70 */ 71 template <class DomainType> class status_error : public status_error<void> 72 { 73 status_code<DomainType> _code; 74 typename DomainType::string_ref _msgref; 75 76 public: 77 //! The type of the status domain 78 using domain_type = DomainType; 79 //! The type of the status code 80 using status_code_type = status_code<DomainType>; 81 82 //! Constructs an instance status_error(status_code<DomainType> code)83 explicit status_error(status_code<DomainType> code) 84 : _code(static_cast<status_code<DomainType> &&>(code)) 85 , _msgref(_code.message()) 86 { 87 } 88 89 //! Return an explanatory string what() const90 virtual const char *what() const noexcept override { return _msgref.c_str(); } // NOLINT 91 92 //! Returns a reference to the code code() const93 const status_code_type &code() const & { return _code; } 94 //! Returns a reference to the code code()95 status_code_type &code() & { return _code; } 96 //! Returns a reference to the code code() const97 const status_code_type &&code() const && { return _code; } 98 //! Returns a reference to the code code()99 status_code_type &&code() && { return _code; } 100 }; 101 102 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END 103 104 #endif 105