base.hpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* Policies for result and outcome
  2. (C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits) and Andrzej Krzemieński <[email protected]> (1 commit)
  3. File Created: Oct 2017
  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_POLICY_BASE_HPP
  26. #define BOOST_OUTCOME_POLICY_BASE_HPP
  27. #include "../detail/value_storage.hpp"
  28. BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
  29. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  30. /*! AWAITING HUGO JSON CONVERSION TOOL
  31. SIGNATURE NOT RECOGNISED
  32. */
  33. namespace hooks
  34. {
  35. /*! AWAITING HUGO JSON CONVERSION TOOL
  36. SIGNATURE NOT RECOGNISED
  37. */
  38. template <class T, class U> constexpr inline void hook_result_construction(T * /*unused*/, U && /*unused*/) noexcept {}
  39. /*! AWAITING HUGO JSON CONVERSION TOOL
  40. SIGNATURE NOT RECOGNISED
  41. */
  42. template <class T, class U> constexpr inline void hook_result_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
  43. /*! AWAITING HUGO JSON CONVERSION TOOL
  44. SIGNATURE NOT RECOGNISED
  45. */
  46. template <class T, class U> constexpr inline void hook_result_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
  47. /*! AWAITING HUGO JSON CONVERSION TOOL
  48. SIGNATURE NOT RECOGNISED
  49. */
  50. template <class T, class U, class... Args>
  51. constexpr inline void hook_result_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
  52. {
  53. }
  54. /*! AWAITING HUGO JSON CONVERSION TOOL
  55. SIGNATURE NOT RECOGNISED
  56. */
  57. template <class T, class... U> constexpr inline void hook_outcome_construction(T * /*unused*/, U &&... /*unused*/) noexcept {}
  58. /*! AWAITING HUGO JSON CONVERSION TOOL
  59. SIGNATURE NOT RECOGNISED
  60. */
  61. template <class T, class U> constexpr inline void hook_outcome_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
  62. /*! AWAITING HUGO JSON CONVERSION TOOL
  63. SIGNATURE NOT RECOGNISED
  64. */
  65. template <class T, class U> constexpr inline void hook_outcome_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
  66. /*! AWAITING HUGO JSON CONVERSION TOOL
  67. SIGNATURE NOT RECOGNISED
  68. */
  69. template <class T, class U, class... Args>
  70. constexpr inline void hook_outcome_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
  71. {
  72. }
  73. } // namespace hooks
  74. #endif
  75. namespace policy
  76. {
  77. namespace detail
  78. {
  79. using BOOST_OUTCOME_V2_NAMESPACE::detail::make_ub;
  80. }
  81. /*! AWAITING HUGO JSON CONVERSION TOOL
  82. SIGNATURE NOT RECOGNISED
  83. */
  84. struct base
  85. {
  86. template <class... Args> static constexpr void _silence_unused(Args &&... /*unused*/) noexcept {}
  87. protected:
  88. template <class Impl> static constexpr void _make_ub(Impl &&self) noexcept { return detail::make_ub(static_cast<Impl &&>(self)); }
  89. template <class Impl> static constexpr bool _has_value(Impl &&self) noexcept { return self._state._status.have_value(); }
  90. template <class Impl> static constexpr bool _has_error(Impl &&self) noexcept { return self._state._status.have_error(); }
  91. template <class Impl> static constexpr bool _has_exception(Impl &&self) noexcept { return self._state._status.have_exception(); }
  92. template <class Impl> static constexpr bool _has_error_is_errno(Impl &&self) noexcept { return self._state._status.have_error_is_errno(); }
  93. template <class Impl> static constexpr void _set_has_value(Impl &&self, bool v) noexcept { self._state._status.set_have_value(v); }
  94. template <class Impl> static constexpr void _set_has_error(Impl &&self, bool v) noexcept { self._state._status.set_have_error(v); }
  95. template <class Impl> static constexpr void _set_has_exception(Impl &&self, bool v) noexcept { self._state._status.set_have_exception(v); }
  96. template <class Impl> static constexpr void _set_has_error_is_errno(Impl &&self, bool v) noexcept { self._state._status.set_have_error_is_errno(v); }
  97. template <class Impl> static constexpr auto &&_value(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._value; }
  98. template <class Impl> static constexpr auto &&_error(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._error; }
  99. public:
  100. template <class R, class S, class P, class NoValuePolicy, class Impl> static inline constexpr auto &&_exception(Impl &&self) noexcept;
  101. template <class T, class U> static constexpr inline void on_result_construction(T *inst, U &&v) noexcept
  102. {
  103. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  104. using namespace hooks;
  105. hook_result_construction(inst, static_cast<U &&>(v));
  106. #else
  107. (void) inst;
  108. (void) v;
  109. #endif
  110. }
  111. template <class T, class U> static constexpr inline void on_result_copy_construction(T *inst, U &&v) noexcept
  112. {
  113. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  114. using namespace hooks;
  115. hook_result_copy_construction(inst, static_cast<U &&>(v));
  116. #else
  117. (void) inst;
  118. (void) v;
  119. #endif
  120. }
  121. template <class T, class U> static constexpr inline void on_result_move_construction(T *inst, U &&v) noexcept
  122. {
  123. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  124. using namespace hooks;
  125. hook_result_move_construction(inst, static_cast<U &&>(v));
  126. #else
  127. (void) inst;
  128. (void) v;
  129. #endif
  130. }
  131. template <class T, class U, class... Args>
  132. static constexpr inline void on_result_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
  133. {
  134. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  135. using namespace hooks;
  136. hook_result_in_place_construction(inst, _, static_cast<Args &&>(args)...);
  137. #else
  138. (void) inst;
  139. (void) _;
  140. _silence_unused(static_cast<Args &&>(args)...);
  141. #endif
  142. }
  143. template <class T, class... U> static constexpr inline void on_outcome_construction(T *inst, U &&... args) noexcept
  144. {
  145. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  146. using namespace hooks;
  147. hook_outcome_construction(inst, static_cast<U &&>(args)...);
  148. #else
  149. (void) inst;
  150. _silence_unused(static_cast<U &&>(args)...);
  151. #endif
  152. }
  153. template <class T, class U> static constexpr inline void on_outcome_copy_construction(T *inst, U &&v) noexcept
  154. {
  155. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  156. using namespace hooks;
  157. hook_outcome_copy_construction(inst, static_cast<U &&>(v));
  158. #else
  159. (void) inst;
  160. (void) v;
  161. #endif
  162. }
  163. template <class T, class U> static constexpr inline void on_outcome_move_construction(T *inst, U &&v) noexcept
  164. {
  165. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  166. using namespace hooks;
  167. hook_outcome_move_construction(inst, static_cast<U &&>(v));
  168. #else
  169. (void) inst;
  170. (void) v;
  171. #endif
  172. }
  173. template <class T, class U, class... Args>
  174. static constexpr inline void on_outcome_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
  175. {
  176. #if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
  177. using namespace hooks;
  178. hook_outcome_in_place_construction(inst, _, static_cast<Args &&>(args)...);
  179. #else
  180. (void) inst;
  181. (void) _;
  182. _silence_unused(static_cast<Args &&>(args)...);
  183. #endif
  184. }
  185. template <class Impl> static constexpr void narrow_value_check(Impl &&self) noexcept
  186. {
  187. if(!_has_value(self))
  188. {
  189. _make_ub(self);
  190. }
  191. }
  192. template <class Impl> static constexpr void narrow_error_check(Impl &&self) noexcept
  193. {
  194. if(!_has_error(self))
  195. {
  196. _make_ub(self);
  197. }
  198. }
  199. template <class Impl> static constexpr void narrow_exception_check(Impl &&self) noexcept
  200. {
  201. if(!_has_exception(self))
  202. {
  203. _make_ub(self);
  204. }
  205. }
  206. };
  207. } // namespace policy
  208. BOOST_OUTCOME_V2_NAMESPACE_END
  209. #endif