errored_status_code.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /* Proposed SG14 status_code
  2. (C) 2018-2024 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
  3. File Created: Jun 2018
  4. Boost Software License - Version 1.0 - August 17th, 2003
  5. Permission is hereby granted, free of charge, to any person or organization
  6. obtaining a copy of the software and accompanying documentation covered by
  7. this license (the "Software") to use, reproduce, display, distribute,
  8. execute, and transmit the Software, and to prepare derivative works of the
  9. Software, and to permit third-parties to whom the Software is furnished to
  10. do so, all subject to the following:
  11. The copyright notices in the Software and this entire statement, including
  12. the above license grant, this restriction and the following disclaimer,
  13. must be included in all copies of the Software, in whole or in part, and
  14. all derivative works of the Software, unless such copies or derivative
  15. works are solely in the form of machine-executable object code generated by
  16. a source language processor.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  20. SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  21. FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  22. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_ERRORED_STATUS_CODE_HPP
  26. #define BOOST_OUTCOME_SYSTEM_ERROR2_ERRORED_STATUS_CODE_HPP
  27. #include "quick_status_code_from_enum.hpp"
  28. BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
  29. /*! A `status_code` which is always a failure. The closest equivalent to
  30. `std::error_code`, except it cannot be modified, and is templated.
  31. Differences from `status_code`:
  32. - Never successful (this contract is checked on construction, if fails then it
  33. terminates the process).
  34. - Is immutable.
  35. */
  36. template <class DomainType> class errored_status_code : public status_code<DomainType>
  37. {
  38. using _base = status_code<DomainType>;
  39. using _base::clear;
  40. using _base::success;
  41. void _check()
  42. {
  43. if(_base::success())
  44. {
  45. std::terminate();
  46. }
  47. }
  48. public:
  49. //! The type of the domain.
  50. using typename _base::domain_type;
  51. //! The type of the error code.
  52. using typename _base::value_type;
  53. //! The type of a reference to a message string.
  54. using typename _base::string_ref;
  55. //! Default constructor.
  56. errored_status_code() = default;
  57. //! Copy constructor.
  58. errored_status_code(const errored_status_code &) = default;
  59. //! Move constructor.
  60. errored_status_code(errored_status_code &&) = default; // NOLINT
  61. //! Copy assignment.
  62. errored_status_code &operator=(const errored_status_code &) = default;
  63. //! Move assignment.
  64. errored_status_code &operator=(errored_status_code &&) = default; // NOLINT
  65. ~errored_status_code() = default;
  66. //! Explicitly construct from any similarly erased status code
  67. explicit errored_status_code(const _base &o) noexcept(std::is_nothrow_copy_constructible<_base>::value)
  68. : _base(o)
  69. {
  70. _check();
  71. }
  72. //! Explicitly construct from any similarly erased status code
  73. explicit errored_status_code(_base &&o) noexcept(std::is_nothrow_move_constructible<_base>::value)
  74. : _base(static_cast<_base &&>(o))
  75. {
  76. _check();
  77. }
  78. /***** KEEP THESE IN SYNC WITH STATUS_CODE *****/
  79. //! Implicit construction from any type where an ADL discovered `make_status_code(T, Args ...)` returns a `status_code`.
  80. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(
  81. class T, class... Args, //
  82. class MakeStatusCodeResult =
  83. typename detail::safe_get_make_status_code_result<T, Args...>::type) // Safe ADL lookup of make_status_code(), returns void if not found
  84. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, errored_status_code>::value // not copy/move of self
  85. && !std::is_same<typename std::decay<T>::type, in_place_t>::value // not in_place_t
  86. && is_status_code<MakeStatusCodeResult>::value // ADL makes a status code
  87. && std::is_constructible<errored_status_code, MakeStatusCodeResult>::value)) // ADLed status code is compatible
  88. errored_status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...))) // NOLINT
  89. : errored_status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
  90. {
  91. _check();
  92. }
  93. //! Implicit construction from any `quick_status_code_from_enum<Enum>` enumerated type.
  94. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class Enum, //
  95. class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type) // Enumeration has been activated
  96. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(std::is_constructible<errored_status_code, QuickStatusCodeType>::value)) // Its status code is compatible
  97. errored_status_code(Enum &&v) noexcept(std::is_nothrow_constructible<errored_status_code, QuickStatusCodeType>::value) // NOLINT
  98. : errored_status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
  99. {
  100. _check();
  101. }
  102. //! Explicit in-place construction.
  103. template <class... Args>
  104. explicit errored_status_code(in_place_t _, Args &&...args) noexcept(std::is_nothrow_constructible<value_type, Args &&...>::value)
  105. : _base(_, static_cast<Args &&>(args)...)
  106. {
  107. _check();
  108. }
  109. //! Explicit in-place construction from initialiser list.
  110. template <class T, class... Args>
  111. explicit errored_status_code(in_place_t _, std::initializer_list<T> il,
  112. Args &&...args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<T>, Args &&...>::value)
  113. : _base(_, il, static_cast<Args &&>(args)...)
  114. {
  115. _check();
  116. }
  117. //! Explicit copy construction from a `value_type`.
  118. explicit errored_status_code(const value_type &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
  119. : _base(v)
  120. {
  121. _check();
  122. }
  123. //! Explicit move construction from a `value_type`.
  124. explicit errored_status_code(value_type &&v) noexcept(std::is_nothrow_move_constructible<value_type>::value)
  125. : _base(static_cast<value_type &&>(v))
  126. {
  127. _check();
  128. }
  129. /*! Explicit construction from an erased status code. Available only if
  130. `value_type` is trivially copyable or move bitcopying, and `sizeof(status_code) <= sizeof(status_code<erased<>>)`.
  131. Does not check if domains are equal.
  132. */
  133. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class ErasedType) //
  134. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<domain_type, detail::erased<ErasedType>>::value))
  135. explicit errored_status_code(const status_code<detail::erased<ErasedType>> &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
  136. : errored_status_code(detail::erasure_cast<value_type>(v.value())) // NOLINT
  137. {
  138. assert(v.domain() == this->domain()); // NOLINT
  139. _check();
  140. }
  141. //! Always false (including at compile time), as errored status codes are never successful.
  142. constexpr bool success() const noexcept { return false; }
  143. //! Return a const reference to the `value_type`.
  144. constexpr const value_type &value() const & noexcept { return this->_value; }
  145. };
  146. namespace traits
  147. {
  148. template <class DomainType> struct is_move_bitcopying<errored_status_code<DomainType>>
  149. {
  150. static constexpr bool value = is_move_bitcopying<typename DomainType::value_type>::value;
  151. };
  152. } // namespace traits
  153. template <class ErasedType> class errored_status_code<detail::erased<ErasedType>> : public status_code<detail::erased<ErasedType>>
  154. {
  155. using _base = status_code<detail::erased<ErasedType>>;
  156. using _base::success;
  157. void _check()
  158. {
  159. if(_base::success())
  160. {
  161. std::terminate();
  162. }
  163. }
  164. public:
  165. using domain_type = typename _base::domain_type;
  166. using value_type = typename _base::value_type;
  167. using string_ref = typename _base::string_ref;
  168. //! Default construction to empty
  169. errored_status_code() = default;
  170. //! Copy constructor
  171. errored_status_code(const errored_status_code &) = default;
  172. //! Move constructor
  173. errored_status_code(errored_status_code &&) = default; // NOLINT
  174. //! Copy assignment
  175. errored_status_code &operator=(const errored_status_code &) = default;
  176. //! Move assignment
  177. errored_status_code &operator=(errored_status_code &&) = default; // NOLINT
  178. ~errored_status_code() = default;
  179. //! Explicitly construct from any similarly erased status code
  180. explicit errored_status_code(const _base &o) noexcept(std::is_nothrow_copy_constructible<_base>::value)
  181. : _base(o)
  182. {
  183. _check();
  184. }
  185. //! Explicitly construct from any similarly erased status code
  186. explicit errored_status_code(_base &&o) noexcept(std::is_nothrow_move_constructible<_base>::value)
  187. : _base(static_cast<_base &&>(o))
  188. {
  189. _check();
  190. }
  191. /***** KEEP THESE IN SYNC WITH STATUS_CODE *****/
  192. //! Implicit copy construction from any other status code if its value type is trivially copyable, it would fit into our storage, and it is not an erased
  193. //! status code.
  194. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType) //
  195. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
  196. BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
  197. errored_status_code(const status_code<DomainType> &v) noexcept
  198. : _base(v) // NOLINT
  199. {
  200. _check();
  201. }
  202. //! Implicit copy construction from any other status code if its value type is trivially copyable and it would fit into our storage, and it is not an erased
  203. //! status code.
  204. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType) //
  205. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
  206. BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
  207. errored_status_code(const errored_status_code<DomainType> &v) noexcept
  208. : _base(static_cast<const status_code<DomainType> &>(v)) // NOLINT
  209. {
  210. _check();
  211. }
  212. //! Implicit move construction from any other status code if its value type is trivially copyable or move bitcopying and it would fit into our storage
  213. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType) //
  214. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
  215. errored_status_code(status_code<DomainType> &&v) noexcept
  216. : _base(static_cast<status_code<DomainType> &&>(v)) // NOLINT
  217. {
  218. _check();
  219. }
  220. //! Implicit move construction from any other status code if its value type is trivially copyable or move bitcopying and it would fit into our storage
  221. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType) //
  222. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
  223. errored_status_code(errored_status_code<DomainType> &&v) noexcept
  224. : _base(static_cast<status_code<DomainType> &&>(v)) // NOLINT
  225. {
  226. _check();
  227. }
  228. //! Implicit construction from any type where an ADL discovered `make_status_code(T, Args ...)` returns a `status_code`.
  229. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(
  230. class T, class... Args, //
  231. class MakeStatusCodeResult =
  232. typename detail::safe_get_make_status_code_result<T, Args...>::type) // Safe ADL lookup of make_status_code(), returns void if not found
  233. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, errored_status_code>::value // not copy/move of self
  234. && !std::is_same<typename std::decay<T>::type, value_type>::value // not copy/move of value type
  235. && is_status_code<MakeStatusCodeResult>::value // ADL makes a status code
  236. && std::is_constructible<errored_status_code, MakeStatusCodeResult>::value)) // ADLed status code is compatible
  237. errored_status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...))) // NOLINT
  238. : errored_status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
  239. {
  240. _check();
  241. }
  242. //! Implicit construction from any `quick_status_code_from_enum<Enum>` enumerated type.
  243. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class Enum, //
  244. class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type) // Enumeration has been activated
  245. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(std::is_constructible<errored_status_code, QuickStatusCodeType>::value)) // Its status code is compatible
  246. errored_status_code(Enum &&v) noexcept(std::is_nothrow_constructible<errored_status_code, QuickStatusCodeType>::value) // NOLINT
  247. : errored_status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
  248. {
  249. _check();
  250. }
  251. #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
  252. //! Explicit copy construction from an unknown status code. Note that this will be empty if its value type is not trivially copyable or would not fit into our
  253. //! storage or the source domain's `_do_erased_copy()` refused the copy.
  254. explicit errored_status_code(in_place_t _, const status_code<void> &v) // NOLINT
  255. : _base(_, v)
  256. {
  257. _check();
  258. }
  259. #endif
  260. //! Always false (including at compile time), as errored status codes are never successful.
  261. constexpr bool success() const noexcept { return false; }
  262. //! Return the erased `value_type` by value.
  263. constexpr value_type value() const noexcept { return this->_value; }
  264. };
  265. /*! An erased type specialisation of `errored_status_code<D>`.
  266. Available only if `ErasedType` satisfies `traits::is_move_bitcopying<ErasedType>::value`.
  267. */
  268. template <class ErasedType> using erased_errored_status_code = errored_status_code<detail::erased<ErasedType>>;
  269. namespace traits
  270. {
  271. template <class ErasedType> struct is_move_bitcopying<errored_status_code<detail::erased<ErasedType>>>
  272. {
  273. static constexpr bool value = true;
  274. };
  275. } // namespace traits
  276. //! True if the status code's are semantically equal via `equivalent()`.
  277. template <class DomainType1, class DomainType2>
  278. inline bool operator==(const errored_status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
  279. {
  280. return a.equivalent(static_cast<const status_code<DomainType2> &>(b));
  281. }
  282. //! True if the status code's are semantically equal via `equivalent()`.
  283. template <class DomainType1, class DomainType2> inline bool operator==(const status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
  284. {
  285. return a.equivalent(static_cast<const status_code<DomainType2> &>(b));
  286. }
  287. //! True if the status code's are semantically equal via `equivalent()`.
  288. template <class DomainType1, class DomainType2> inline bool operator==(const errored_status_code<DomainType1> &a, const status_code<DomainType2> &b) noexcept
  289. {
  290. return static_cast<const status_code<DomainType1> &>(a).equivalent(b);
  291. }
  292. //! True if the status code's are not semantically equal via `equivalent()`.
  293. template <class DomainType1, class DomainType2>
  294. inline bool operator!=(const errored_status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
  295. {
  296. return !a.equivalent(static_cast<const status_code<DomainType2> &>(b));
  297. }
  298. //! True if the status code's are not semantically equal via `equivalent()`.
  299. template <class DomainType1, class DomainType2> inline bool operator!=(const status_code<DomainType1> &a, const errored_status_code<DomainType2> &b) noexcept
  300. {
  301. return !a.equivalent(static_cast<const status_code<DomainType2> &>(b));
  302. }
  303. //! True if the status code's are not semantically equal via `equivalent()`.
  304. template <class DomainType1, class DomainType2> inline bool operator!=(const errored_status_code<DomainType1> &a, const status_code<DomainType2> &b) noexcept
  305. {
  306. return !static_cast<const status_code<DomainType1> &>(a).equivalent(b);
  307. }
  308. //! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
  309. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType1, class T, //
  310. class MakeStatusCodeResult =
  311. typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
  312. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
  313. inline bool operator==(const errored_status_code<DomainType1> &a, const T &b)
  314. {
  315. return a.equivalent(make_status_code(b));
  316. }
  317. //! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
  318. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class T, class DomainType1, //
  319. class MakeStatusCodeResult =
  320. typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
  321. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
  322. inline bool operator==(const T &a, const errored_status_code<DomainType1> &b)
  323. {
  324. return b.equivalent(make_status_code(a));
  325. }
  326. //! True if the status code's are not semantically equal via `equivalent()` to `make_status_code(T)`.
  327. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType1, class T, //
  328. class MakeStatusCodeResult =
  329. typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
  330. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
  331. inline bool operator!=(const errored_status_code<DomainType1> &a, const T &b)
  332. {
  333. return !a.equivalent(make_status_code(b));
  334. }
  335. //! True if the status code's are semantically equal via `equivalent()` to `make_status_code(T)`.
  336. BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class T, class DomainType1, //
  337. class MakeStatusCodeResult =
  338. typename detail::safe_get_make_status_code_result<const T &>::type) // Safe ADL lookup of make_status_code(), returns void if not found
  339. BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(is_status_code<MakeStatusCodeResult>::value)) // ADL makes a status code
  340. inline bool operator!=(const T &a, const errored_status_code<DomainType1> &b)
  341. {
  342. return !b.equivalent(make_status_code(a));
  343. }
  344. //! True if the status code's are semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(b)`.
  345. template <class DomainType1, class T, //
  346. class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
  347. >
  348. inline bool operator==(const errored_status_code<DomainType1> &a, const T &b)
  349. {
  350. return a.equivalent(QuickStatusCodeType(b));
  351. }
  352. //! True if the status code's are semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(a)`.
  353. template <class T, class DomainType1, //
  354. class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
  355. >
  356. inline bool operator==(const T &a, const errored_status_code<DomainType1> &b)
  357. {
  358. return b.equivalent(QuickStatusCodeType(a));
  359. }
  360. //! True if the status code's are not semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(b)`.
  361. template <class DomainType1, class T, //
  362. class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
  363. >
  364. inline bool operator!=(const errored_status_code<DomainType1> &a, const T &b)
  365. {
  366. return !a.equivalent(QuickStatusCodeType(b));
  367. }
  368. //! True if the status code's are not semantically equal via `equivalent()` to `quick_status_code_from_enum<T>::code_type(a)`.
  369. template <class T, class DomainType1, //
  370. class QuickStatusCodeType = typename quick_status_code_from_enum<T>::code_type // Enumeration has been activated
  371. >
  372. inline bool operator!=(const T &a, const errored_status_code<DomainType1> &b)
  373. {
  374. return !b.equivalent(QuickStatusCodeType(a));
  375. }
  376. namespace detail
  377. {
  378. template <class T> struct is_errored_status_code
  379. {
  380. static constexpr bool value = false;
  381. };
  382. template <class T> struct is_errored_status_code<errored_status_code<T>>
  383. {
  384. static constexpr bool value = true;
  385. };
  386. template <class T> struct is_erased_errored_status_code
  387. {
  388. static constexpr bool value = false;
  389. };
  390. template <class T> struct is_erased_errored_status_code<errored_status_code<erased<T>>>
  391. {
  392. static constexpr bool value = true;
  393. };
  394. } // namespace detail
  395. //! Trait returning true if the type is an errored status code.
  396. template <class T> struct is_errored_status_code
  397. {
  398. static constexpr bool value =
  399. detail::is_errored_status_code<typename std::decay<T>::type>::value || detail::is_erased_errored_status_code<typename std::decay<T>::type>::value;
  400. };
  401. BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
  402. #endif