system_error.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  3. // Copyright (c) 2022 Dmitry Arkhipov ([email protected])
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Official repository: https://github.com/boostorg/json
  9. //
  10. #ifndef BOOST_JSON_SYSTEM_ERROR_HPP
  11. #define BOOST_JSON_SYSTEM_ERROR_HPP
  12. #include <boost/json/detail/config.hpp>
  13. #include <boost/json/fwd.hpp>
  14. #include <boost/assert/source_location.hpp>
  15. #include <boost/json/result_for.hpp>
  16. #include <boost/system/error_code.hpp>
  17. #include <boost/system/result.hpp>
  18. #include <boost/system/system_error.hpp>
  19. namespace boost {
  20. namespace json {
  21. /** The type of error code used by the library.
  22. @note This alias is deprecated in favor of `boost::system::error_code`.
  23. It is included for backwards compatibility and shouldn't be used in new
  24. code. It will be removed completely in version 1.87.0.
  25. */
  26. typedef boost::system::error_code
  27. BOOST_DEPRECATED("Use boost::system::error_code instead")
  28. error_code;
  29. /** The type of error category used by the library.
  30. @note This alias is deprecated in favor of `boost::system::error_category`.
  31. It is included for backwards compatibility and shouldn't be used in new
  32. code. It will be removed completely in version 1.87.0.
  33. */
  34. typedef boost::system::error_category
  35. BOOST_DEPRECATED("Use boost::system::error_category instead")
  36. error_category;
  37. /** The type of error condition used by the library.
  38. @note This alias is deprecated in favor of
  39. `boost::system::error_condition`. It is included for backwards
  40. compatibility and shouldn't be used in new code. It will be removed
  41. completely in version 1.87.0.
  42. */
  43. typedef boost::system::error_condition
  44. BOOST_DEPRECATED("Use boost::system::error_condition instead")
  45. error_condition;
  46. /** The type of system error thrown by the library.
  47. @note This alias is deprecated in favor of `boost::system::system_error`.
  48. It is included for backwards compatibility and shouldn't be used in new
  49. code. It will be removed completely in version 1.87.0.
  50. */
  51. typedef boost::system::system_error
  52. BOOST_DEPRECATED("Use boost::system::system_error instead")
  53. system_error;
  54. /** The type of result returned by library functions
  55. This is an alias template used as the return type for functions that can
  56. either return a value, or fail with an error code. This is a brief
  57. synopsis of the type:
  58. @par Declaration
  59. @code
  60. template< class T >
  61. class result
  62. {
  63. public:
  64. // Return true if the result contains an error
  65. constexpr bool has_error() const noexcept;
  66. // These two return true if the result contains a value
  67. constexpr bool has_value() const noexcept;
  68. constexpr explicit operator bool() const noexcept;
  69. // Return the value or throw an exception if has_value() == false
  70. constexpr T& value();
  71. constexpr T const& value() const;
  72. // Return the value, assuming the result contains it
  73. constexpr T& operator*();
  74. constexpr T const& operator*() const;
  75. // Return the error, which is default constructed if has_error() == false
  76. constexpr error_code error() const noexcept;
  77. ...more
  78. };
  79. @endcode
  80. @par Usage
  81. Given the function @ref try_value_to with this signature:
  82. @code
  83. template< class T>
  84. result< T > try_value_to( const value& jv );
  85. @endcode
  86. The following statement captures the value in a variable upon success,
  87. otherwise throws:
  88. @code
  89. int n = try_value_to<int>( jv ).value();
  90. @endcode
  91. This statement captures the result in a variable and inspects the error
  92. condition:
  93. @code
  94. result< int > r = try_value_to<int>( jv );
  95. if( r )
  96. std::cout << *r;
  97. else
  98. std::cout << r.error();
  99. @endcode
  100. @note This alias is deprecated in favor of `boost::system::result`. It is
  101. included for backwards compatibility and shouldn't be used in new code. It
  102. will be removed completely in version 1.87.0.
  103. @tparam T The type of value held by the result.
  104. */
  105. template< class T >
  106. using
  107. result
  108. #ifndef BOOST_MSVC
  109. BOOST_DEPRECATED("Use boost::system::result instead")
  110. #endif
  111. = boost::system::result<T>;
  112. } // namespace json
  113. } // namespace boost
  114. #endif