config.hpp 18 KB

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