config.hpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* Configure Boost.Outcome with Boost
  2. (C) 2015-2019 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. namespace boost
  109. {
  110. #define BOOST_OUTCOME_V2
  111. //! The Boost.Outcome namespace
  112. namespace outcome_v2
  113. {
  114. }
  115. }
  116. /*! The namespace of this Boost.Outcome v2.
  117. */
  118. #define BOOST_OUTCOME_V2_NAMESPACE boost::outcome_v2
  119. /*! Expands into the appropriate namespace markup to enter the Boost.Outcome v2 namespace.
  120. */
  121. #define BOOST_OUTCOME_V2_NAMESPACE_BEGIN \
  122. namespace boost \
  123. { \
  124. namespace outcome_v2 \
  125. {
  126. /*! Expands into the appropriate namespace markup to enter the C++ module
  127. exported Boost.Outcome v2 namespace.
  128. */
  129. #define BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN \
  130. namespace boost \
  131. { \
  132. namespace outcome_v2 \
  133. {
  134. /*! \brief Expands into the appropriate namespace markup to exit the Boost.Outcome v2 namespace.
  135. \ingroup config
  136. */
  137. #define BOOST_OUTCOME_V2_NAMESPACE_END \
  138. } \
  139. }
  140. #include <cstdint> // for uint32_t etc
  141. #include <initializer_list>
  142. #include <iosfwd> // for future serialisation
  143. #include <new> // for placement in moves etc
  144. #include <type_traits>
  145. #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
  146. #if defined(_MSC_VER) && _HAS_CXX17
  147. #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
  148. #elif __cplusplus >= 201700
  149. // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
  150. #ifdef __has_include
  151. #if !__has_include(<variant>)
  152. #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
  153. #endif
  154. #endif
  155. #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
  156. #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1
  157. #endif
  158. #else
  159. #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0
  160. #endif
  161. #endif
  162. #if BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
  163. #include <utility> // for in_place_type_t
  164. BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  165. template <class T> using in_place_type_t = std::in_place_type_t<T>;
  166. using std::in_place_type;
  167. BOOST_OUTCOME_V2_NAMESPACE_END
  168. #else
  169. BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  170. //! Aliases `std::in_place_type_t<T>` if on C++ 17 or later, else defined locally.
  171. template <class T> struct in_place_type_t
  172. {
  173. explicit in_place_type_t() = default;
  174. };
  175. //! Aliases `std::in_place_type<T>` if on C++ 17 or later, else defined locally.
  176. template <class T> constexpr in_place_type_t<T> in_place_type{};
  177. BOOST_OUTCOME_V2_NAMESPACE_END
  178. #endif
  179. #ifndef BOOST_OUTCOME_TRIVIAL_ABI
  180. #if defined(STANDARDESE_IS_IN_THE_HOUSE) || __clang_major__ >= 7
  181. //! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
  182. #define BOOST_OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
  183. #else
  184. #define BOOST_OUTCOME_TRIVIAL_ABI
  185. #endif
  186. #endif
  187. BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  188. namespace detail
  189. {
  190. // Test if type is an in_place_type_t
  191. template <class T> struct is_in_place_type_t
  192. {
  193. static constexpr bool value = false;
  194. };
  195. template <class U> struct is_in_place_type_t<in_place_type_t<U>>
  196. {
  197. static constexpr bool value = true;
  198. };
  199. // Replace void with constructible void_type
  200. struct empty_type
  201. {
  202. };
  203. struct void_type
  204. {
  205. // We always compare true to another instance of me
  206. constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
  207. constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
  208. };
  209. template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
  210. template <class Output, class Input> using rebind_type5 = Output;
  211. template <class Output, class Input>
  212. using rebind_type4 = std::conditional_t< //
  213. std::is_volatile<Input>::value, //
  214. std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
  215. rebind_type5<Output, Input>>;
  216. template <class Output, class Input>
  217. using rebind_type3 = std::conditional_t< //
  218. std::is_const<Input>::value, //
  219. std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
  220. rebind_type4<Output, Input>>;
  221. template <class Output, class Input>
  222. using rebind_type2 = std::conditional_t< //
  223. std::is_lvalue_reference<Input>::value, //
  224. std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
  225. rebind_type3<Output, Input>>;
  226. template <class Output, class Input>
  227. using rebind_type = std::conditional_t< //
  228. std::is_rvalue_reference<Input>::value, //
  229. std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
  230. rebind_type2<Output, Input>>;
  231. // static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
  232. /* True if type is the same or constructible. Works around a bug where clang + libstdc++
  233. pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
  234. */
  235. template <class T, class U> struct _is_explicitly_constructible
  236. {
  237. static constexpr bool value = std::is_constructible<T, U>::value;
  238. };
  239. template <class T> struct _is_explicitly_constructible<T, void>
  240. {
  241. static constexpr bool value = false;
  242. };
  243. template <> struct _is_explicitly_constructible<void, void>
  244. {
  245. static constexpr bool value = false;
  246. };
  247. template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
  248. template <class T, class U> struct _is_implicitly_constructible
  249. {
  250. static constexpr bool value = std::is_convertible<U, T>::value;
  251. };
  252. template <class T> struct _is_implicitly_constructible<T, void>
  253. {
  254. static constexpr bool value = false;
  255. };
  256. template <> struct _is_implicitly_constructible<void, void>
  257. {
  258. static constexpr bool value = false;
  259. };
  260. template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
  261. #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
  262. #if defined(_MSC_VER) && _HAS_CXX17
  263. #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
  264. #elif __cplusplus >= 201700
  265. // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
  266. #ifdef __has_include
  267. #if !__has_include(<variant>)
  268. #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 // must have it if <variant> is present
  269. #endif
  270. #endif
  271. #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
  272. #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
  273. #endif
  274. #else
  275. #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
  276. #endif
  277. #endif
  278. // True if type is nothrow swappable
  279. #if !defined(STANDARDESE_IS_IN_THE_HOUSE) && BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
  280. template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
  281. #else
  282. template <class T> struct is_nothrow_swappable
  283. {
  284. static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
  285. };
  286. #endif
  287. } // namespace detail
  288. BOOST_OUTCOME_V2_NAMESPACE_END
  289. #ifndef BOOST_OUTCOME_THROW_EXCEPTION
  290. #include <boost/throw_exception.hpp>
  291. #define BOOST_OUTCOME_THROW_EXCEPTION(expr) BOOST_THROW_EXCEPTION(expr)
  292. #endif
  293. #ifndef BOOST_OUTCOME_AUTO_TEST_CASE
  294. #define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a)
  295. #endif
  296. #endif