config.hpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /* Configure Boost.Outcome with Boost
  2. (C) 2015-2024 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
  3. File Created: August 2015
  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_V2_CONFIG_HPP
  26. #define BOOST_OUTCOME_V2_CONFIG_HPP
  27. #include "detail/version.hpp"
  28. // Pull in detection of __MINGW64_VERSION_MAJOR
  29. #if defined(__MINGW32__) && !defined(DOXYGEN_IS_IN_THE_HOUSE)
  30. #include <_mingw.h>
  31. #endif
  32. #include <boost/config.hpp>
  33. #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
  34. #error Boost.Outcome needs variadic template support in the compiler
  35. #endif
  36. #if defined(BOOST_NO_CXX14_CONSTEXPR) && _MSC_FULL_VER < 191100000
  37. #error Boost.Outcome needs constexpr (C++ 14) support in the compiler
  38. #endif
  39. #ifdef BOOST_NO_CXX14_VARIABLE_TEMPLATES
  40. #error Boost.Outcome needs variable template support in the compiler
  41. #endif
  42. #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6
  43. #error Due to a bug in nested template variables parsing, Boost.Outcome does not work on GCCs earlier than v6.
  44. #endif
  45. #ifndef BOOST_OUTCOME_SYMBOL_VISIBLE
  46. #define BOOST_OUTCOME_SYMBOL_VISIBLE BOOST_SYMBOL_VISIBLE
  47. #endif
  48. #ifdef __has_cpp_attribute
  49. #define BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(attr) __has_cpp_attribute(attr)
  50. #else
  51. #define BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(attr) (0)
  52. #endif
  53. // Weird that Boost.Config doesn't define a BOOST_NO_CXX17_NODISCARD
  54. #ifndef BOOST_OUTCOME_NODISCARD
  55. #if BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(nodiscard)
  56. #define BOOST_OUTCOME_NODISCARD [[nodiscard]]
  57. #elif defined(__clang__) // deliberately not GCC
  58. #define BOOST_OUTCOME_NODISCARD __attribute__((warn_unused_result))
  59. #elif defined(_MSC_VER)
  60. // _Must_inspect_result_ expands into this
  61. #define BOOST_OUTCOME_NODISCARD \
  62. __declspec( \
  63. "SAL_name" \
  64. "(" \
  65. "\"_Must_inspect_result_\"" \
  66. "," \
  67. "\"\"" \
  68. "," \
  69. "\"2\"" \
  70. ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
  71. #endif
  72. #endif
  73. #ifndef BOOST_OUTCOME_NODISCARD
  74. #define BOOST_OUTCOME_NODISCARD
  75. #endif
  76. #ifndef BOOST_OUTCOME_THREAD_LOCAL
  77. #ifndef BOOST_NO_CXX11_THREAD_LOCAL
  78. #define BOOST_OUTCOME_THREAD_LOCAL thread_local
  79. #else
  80. #if defined(_MSC_VER)
  81. #define BOOST_OUTCOME_THREAD_LOCAL __declspec(thread)
  82. #elif defined(__GNUC__)
  83. #define BOOST_OUTCOME_THREAD_LOCAL __thread
  84. #else
  85. #error Unknown compiler, cannot set BOOST_OUTCOME_THREAD_LOCAL
  86. #endif
  87. #endif
  88. #endif
  89. // Can't use the QuickCppLib preprocessor metaprogrammed Concepts TS support, so ...
  90. #ifndef BOOST_OUTCOME_TEMPLATE
  91. #define BOOST_OUTCOME_TEMPLATE(...) template <__VA_ARGS__
  92. #endif
  93. #ifndef BOOST_OUTCOME_TREQUIRES
  94. #define BOOST_OUTCOME_TREQUIRES(...) , __VA_ARGS__ >
  95. #endif
  96. #ifndef BOOST_OUTCOME_TEXPR
  97. #define BOOST_OUTCOME_TEXPR(...) typename = decltype(__VA_ARGS__)
  98. #endif
  99. #ifndef BOOST_OUTCOME_TPRED
  100. #define BOOST_OUTCOME_TPRED(...) typename = std::enable_if_t<__VA_ARGS__>
  101. #endif
  102. #ifndef BOOST_OUTCOME_REQUIRES
  103. #if defined(__cpp_concepts) && (!defined(_MSC_VER) || _MSC_FULL_VER >= 192400000) // VS 2019 16.3 is broken here
  104. #define BOOST_OUTCOME_REQUIRES(...) requires(__VA_ARGS__)
  105. #else
  106. #define BOOST_OUTCOME_REQUIRES(...)
  107. #endif
  108. #endif
  109. #ifndef BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR
  110. #define BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 220 // the v2.2 Outcome release
  111. #endif
  112. namespace boost
  113. {
  114. #define BOOST_OUTCOME_V2
  115. //! The Boost.Outcome namespace
  116. namespace outcome_v2
  117. {
  118. }
  119. }
  120. /*! The namespace of this Boost.Outcome v2.
  121. */
  122. #define BOOST_OUTCOME_V2_NAMESPACE boost::outcome_v2
  123. /*! Expands into the appropriate namespace markup to enter the Boost.Outcome v2 namespace.
  124. */
  125. #define BOOST_OUTCOME_V2_NAMESPACE_BEGIN \
  126. namespace boost \
  127. { \
  128. namespace outcome_v2 \
  129. {
  130. /*! Expands into the appropriate namespace markup to enter the C++ module
  131. exported Boost.Outcome v2 namespace.
  132. */
  133. #define BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN \
  134. namespace boost \
  135. { \
  136. namespace outcome_v2 \
  137. {
  138. /*! \brief Expands into the appropriate namespace markup to exit the Boost.Outcome v2 namespace.
  139. \ingroup config
  140. */
  141. #define BOOST_OUTCOME_V2_NAMESPACE_END \
  142. } \
  143. }
  144. #include <cstdint> // for uint32_t etc
  145. #include <initializer_list>
  146. #include <iosfwd> // for future serialisation
  147. #include <new> // for placement in moves etc
  148. #include <type_traits>
  149. #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
  150. #if defined(_MSC_VER) && _HAS_CXX17
  151. #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
  152. #elif __cplusplus >= 201700
  153. // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
  154. #ifdef __has_include
  155. #if !__has_include(<variant>)
  156. #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
  157. #endif
  158. #endif
  159. #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
  160. #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1
  161. #endif
  162. #else
  163. #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0
  164. #endif
  165. #endif
  166. #if BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
  167. #include <utility> // for in_place_type_t
  168. BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  169. template <class T> using in_place_type_t = std::in_place_type_t<T>;
  170. using std::in_place_type;
  171. BOOST_OUTCOME_V2_NAMESPACE_END
  172. #else
  173. BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  174. //! Aliases `std::in_place_type_t<T>` if on C++ 17 or later, else defined locally.
  175. template <class T> struct in_place_type_t
  176. {
  177. explicit in_place_type_t() = default;
  178. };
  179. //! Aliases `std::in_place_type<T>` if on C++ 17 or later, else defined locally.
  180. template <class T> constexpr in_place_type_t<T> in_place_type{};
  181. BOOST_OUTCOME_V2_NAMESPACE_END
  182. #endif
  183. #if defined(BOOST_OUTCOME_USE_STD_ADDRESSOF) && !BOOST_OUTCOME_USE_STD_ADDRESSOF
  184. #define BOOST_OUTCOME_ADDRESS_OF(...) (&__VA_ARGS__)
  185. #else
  186. #include <memory> // for std::addressof
  187. #define BOOST_OUTCOME_ADDRESS_OF(...) std::addressof(__VA_ARGS__)
  188. #endif
  189. #ifndef BOOST_OUTCOME_ASSERT
  190. #include <boost/assert.hpp>
  191. #define BOOST_OUTCOME_ASSERT(...) BOOST_ASSERT(__VA_ARGS__)
  192. #endif
  193. #ifndef BOOST_OUTCOME_TRIVIAL_ABI
  194. #if defined(STANDARDESE_IS_IN_THE_HOUSE) || __clang_major__ >= 7
  195. //! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
  196. #define BOOST_OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
  197. #else
  198. #define BOOST_OUTCOME_TRIVIAL_ABI
  199. #endif
  200. #endif
  201. BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  202. namespace detail
  203. {
  204. // Test if type is an in_place_type_t
  205. template <class T> struct is_in_place_type_t
  206. {
  207. static constexpr bool value = false;
  208. };
  209. template <class U> struct is_in_place_type_t<in_place_type_t<U>>
  210. {
  211. static constexpr bool value = true;
  212. };
  213. // Replace void with constructible void_type
  214. struct empty_type
  215. {
  216. };
  217. struct void_type
  218. {
  219. // We always compare true to another instance of me
  220. constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
  221. constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
  222. };
  223. template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
  224. template <class Output, class Input> using rebind_type5 = Output;
  225. template <class Output, class Input>
  226. using rebind_type4 = std::conditional_t< //
  227. std::is_volatile<Input>::value, //
  228. std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
  229. rebind_type5<Output, Input>>;
  230. template <class Output, class Input>
  231. using rebind_type3 = std::conditional_t< //
  232. std::is_const<Input>::value, //
  233. std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
  234. rebind_type4<Output, Input>>;
  235. template <class Output, class Input>
  236. using rebind_type2 = std::conditional_t< //
  237. std::is_lvalue_reference<Input>::value, //
  238. std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
  239. rebind_type3<Output, Input>>;
  240. template <class Output, class Input>
  241. using rebind_type = std::conditional_t< //
  242. std::is_rvalue_reference<Input>::value, //
  243. std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
  244. rebind_type2<Output, Input>>;
  245. // static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
  246. /* True if type is the same or constructible. Works around a bug where clang + libstdc++
  247. pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
  248. */
  249. template <class T, class U> struct _is_explicitly_constructible
  250. {
  251. static constexpr bool value = std::is_constructible<T, U>::value;
  252. };
  253. template <class T> struct _is_explicitly_constructible<T, void>
  254. {
  255. static constexpr bool value = false;
  256. };
  257. template <> struct _is_explicitly_constructible<void, void>
  258. {
  259. static constexpr bool value = false;
  260. };
  261. template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
  262. template <class T, class U> struct _is_implicitly_constructible
  263. {
  264. static constexpr bool value = std::is_convertible<U, T>::value;
  265. };
  266. template <class T> struct _is_implicitly_constructible<T, void>
  267. {
  268. static constexpr bool value = false;
  269. };
  270. template <> struct _is_implicitly_constructible<void, void>
  271. {
  272. static constexpr bool value = false;
  273. };
  274. template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
  275. template <class T, class... Args> struct _is_nothrow_constructible
  276. {
  277. static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value;
  278. };
  279. template <class T> struct _is_nothrow_constructible<T, void>
  280. {
  281. static constexpr bool value = false;
  282. };
  283. template <> struct _is_nothrow_constructible<void, void>
  284. {
  285. static constexpr bool value = false;
  286. };
  287. template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value;
  288. template <class T, class... Args> struct _is_constructible
  289. {
  290. static constexpr bool value = std::is_constructible<T, Args...>::value;
  291. };
  292. template <class T> struct _is_constructible<T, void>
  293. {
  294. static constexpr bool value = false;
  295. };
  296. template <> struct _is_constructible<void, void>
  297. {
  298. static constexpr bool value = false;
  299. };
  300. template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value;
  301. #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
  302. #if defined(_MSC_VER) && _HAS_CXX17
  303. #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
  304. #elif __cplusplus >= 201700
  305. // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
  306. #ifdef __has_include
  307. #if !__has_include(<variant>)
  308. #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 // must have it if <variant> is present
  309. #endif
  310. #endif
  311. #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
  312. #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
  313. #endif
  314. #else
  315. #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
  316. #endif
  317. #endif
  318. // True if type is nothrow swappable
  319. #if !defined(STANDARDESE_IS_IN_THE_HOUSE) && BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
  320. template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
  321. #else
  322. template <class T> struct is_nothrow_swappable
  323. {
  324. static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
  325. };
  326. #endif
  327. } // namespace detail
  328. BOOST_OUTCOME_V2_NAMESPACE_END
  329. #ifndef BOOST_OUTCOME_THROW_EXCEPTION
  330. #include <boost/throw_exception.hpp>
  331. #define BOOST_OUTCOME_THROW_EXCEPTION(expr) BOOST_THROW_EXCEPTION(expr)
  332. #endif
  333. #ifndef BOOST_OUTCOME_AUTO_TEST_CASE
  334. #define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a)
  335. #endif
  336. #endif