config.hpp 16 KB

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