1 /* Configure Boost.Outcome with Boost
2 (C) 2015-2020 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
3 File Created: August 2015
6 Boost Software License - Version 1.0 - August 17th, 2003
8 Permission is hereby granted, free of charge, to any person or organization
9 obtaining a copy of the software and accompanying documentation covered by
10 this license (the "Software") to use, reproduce, display, distribute,
11 execute, and transmit the Software, and to prepare derivative works of the
12 Software, and to permit third-parties to whom the Software is furnished to
13 do so, all subject to the following:
15 The copyright notices in the Software and this entire statement, including
16 the above license grant, this restriction and the following disclaimer,
17 must be included in all copies of the Software, in whole or in part, and
18 all derivative works of the Software, unless such copies or derivative
19 works are solely in the form of machine-executable object code generated by
20 a source language processor.
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
25 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
26 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
27 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 DEALINGS IN THE SOFTWARE.
31 #ifndef BOOST_OUTCOME_V2_CONFIG_HPP
32 #define BOOST_OUTCOME_V2_CONFIG_HPP
34 #include "detail/version.hpp"
36 // Pull in detection of __MINGW64_VERSION_MAJOR
37 #if defined(__MINGW32__) && !defined(DOXYGEN_IS_IN_THE_HOUSE)
41 #include <boost/config.hpp>
43 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
44 #error Boost.Outcome needs variadic template support in the compiler
46 #if defined(BOOST_NO_CXX14_CONSTEXPR) && _MSC_FULL_VER < 191100000
47 #error Boost.Outcome needs constexpr (C++ 14) support in the compiler
49 #ifdef BOOST_NO_CXX14_VARIABLE_TEMPLATES
50 #error Boost.Outcome needs variable template support in the compiler
52 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6
53 #error Due to a bug in nested template variables parsing, Boost.Outcome does not work on GCCs earlier than v6.
56 #ifndef BOOST_OUTCOME_SYMBOL_VISIBLE
57 #define BOOST_OUTCOME_SYMBOL_VISIBLE BOOST_SYMBOL_VISIBLE
59 #ifdef __has_cpp_attribute
60 #define BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(attr) __has_cpp_attribute(attr)
62 #define BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(attr) (0)
64 // Weird that Boost.Config doesn't define a BOOST_NO_CXX17_NODISCARD
65 #ifndef BOOST_OUTCOME_NODISCARD
66 #if BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(nodiscard)
67 #define BOOST_OUTCOME_NODISCARD [[nodiscard]]
68 #elif defined(__clang__) // deliberately not GCC
69 #define BOOST_OUTCOME_NODISCARD __attribute__((warn_unused_result))
70 #elif defined(_MSC_VER)
71 // _Must_inspect_result_ expands into this
72 #define BOOST_OUTCOME_NODISCARD \
73 __declspec("SAL_name" \
75 "\"_Must_inspect_result_\"" \
80 ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
83 #ifndef BOOST_OUTCOME_NODISCARD
84 #define BOOST_OUTCOME_NODISCARD
86 #ifndef BOOST_OUTCOME_THREAD_LOCAL
87 #ifndef BOOST_NO_CXX11_THREAD_LOCAL
88 #define BOOST_OUTCOME_THREAD_LOCAL thread_local
91 #define BOOST_OUTCOME_THREAD_LOCAL __declspec(thread)
92 #elif defined(__GNUC__)
93 #define BOOST_OUTCOME_THREAD_LOCAL __thread
95 #error Unknown compiler, cannot set BOOST_OUTCOME_THREAD_LOCAL
99 // Can't use the QuickCppLib preprocessor metaprogrammed Concepts TS support, so ...
100 #ifndef BOOST_OUTCOME_TEMPLATE
101 #define BOOST_OUTCOME_TEMPLATE(...) template <__VA_ARGS__
103 #ifndef BOOST_OUTCOME_TREQUIRES
104 #define BOOST_OUTCOME_TREQUIRES(...) , __VA_ARGS__ >
106 #ifndef BOOST_OUTCOME_TEXPR
107 #define BOOST_OUTCOME_TEXPR(...) typename = decltype(__VA_ARGS__)
109 #ifndef BOOST_OUTCOME_TPRED
110 #define BOOST_OUTCOME_TPRED(...) typename = std::enable_if_t<__VA_ARGS__>
112 #ifndef BOOST_OUTCOME_REQUIRES
113 #if defined(__cpp_concepts) && (!defined(_MSC_VER) || _MSC_FULL_VER >= 192400000) // VS 2019 16.3 is broken here
114 #define BOOST_OUTCOME_REQUIRES(...) requires(__VA_ARGS__)
116 #define BOOST_OUTCOME_REQUIRES(...)
120 #ifndef BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR
121 #define BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 210 // the v2.1 Outcome release
126 #define BOOST_OUTCOME_V2
127 //! The Boost.Outcome namespace
132 /*! The namespace of this Boost.Outcome v2.
134 #define BOOST_OUTCOME_V2_NAMESPACE boost::outcome_v2
135 /*! Expands into the appropriate namespace markup to enter the Boost.Outcome v2 namespace.
137 #define BOOST_OUTCOME_V2_NAMESPACE_BEGIN \
140 namespace outcome_v2 \
142 /*! Expands into the appropriate namespace markup to enter the C++ module
143 exported Boost.Outcome v2 namespace.
145 #define BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN \
148 namespace outcome_v2 \
150 /*! \brief Expands into the appropriate namespace markup to exit the Boost.Outcome v2 namespace.
153 #define BOOST_OUTCOME_V2_NAMESPACE_END \
157 #include <cstdint> // for uint32_t etc
158 #include <initializer_list>
159 #include <iosfwd> // for future serialisation
160 #include <new> // for placement in moves etc
161 #include <type_traits>
163 #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
164 #if defined(_MSC_VER) && _HAS_CXX17
165 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
166 #elif __cplusplus >= 201700
167 // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
169 #if !__has_include(<variant>)
170 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
174 #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
175 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1
178 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0
182 #if BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
183 #include <utility> // for in_place_type_t
185 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
186 template <class T> using in_place_type_t = std::in_place_type_t<T>;
187 using std::in_place_type;
188 BOOST_OUTCOME_V2_NAMESPACE_END
190 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
191 //! Aliases `std::in_place_type_t<T>` if on C++ 17 or later, else defined locally.
192 template <class T> struct in_place_type_t
194 explicit in_place_type_t() = default;
196 //! Aliases `std::in_place_type<T>` if on C++ 17 or later, else defined locally.
197 template <class T> constexpr in_place_type_t<T> in_place_type{};
198 BOOST_OUTCOME_V2_NAMESPACE_END
201 #ifndef BOOST_OUTCOME_TRIVIAL_ABI
202 #if defined(STANDARDESE_IS_IN_THE_HOUSE) || __clang_major__ >= 7
203 //! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
204 #define BOOST_OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
206 #define BOOST_OUTCOME_TRIVIAL_ABI
210 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
213 // Test if type is an in_place_type_t
214 template <class T> struct is_in_place_type_t
216 static constexpr bool value = false;
218 template <class U> struct is_in_place_type_t<in_place_type_t<U>>
220 static constexpr bool value = true;
223 // Replace void with constructible void_type
229 // We always compare true to another instance of me
230 constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
231 constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
233 template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
235 template <class Output, class Input> using rebind_type5 = Output;
236 template <class Output, class Input>
237 using rebind_type4 = std::conditional_t< //
238 std::is_volatile<Input>::value, //
239 std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
240 rebind_type5<Output, Input>>;
241 template <class Output, class Input>
242 using rebind_type3 = std::conditional_t< //
243 std::is_const<Input>::value, //
244 std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
245 rebind_type4<Output, Input>>;
246 template <class Output, class Input>
247 using rebind_type2 = std::conditional_t< //
248 std::is_lvalue_reference<Input>::value, //
249 std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
250 rebind_type3<Output, Input>>;
251 template <class Output, class Input>
252 using rebind_type = std::conditional_t< //
253 std::is_rvalue_reference<Input>::value, //
254 std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
255 rebind_type2<Output, Input>>;
257 // static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
260 /* True if type is the same or constructible. Works around a bug where clang + libstdc++
261 pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
263 template <class T, class U> struct _is_explicitly_constructible
265 static constexpr bool value = std::is_constructible<T, U>::value;
267 template <class T> struct _is_explicitly_constructible<T, void>
269 static constexpr bool value = false;
271 template <> struct _is_explicitly_constructible<void, void>
273 static constexpr bool value = false;
275 template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
277 template <class T, class U> struct _is_implicitly_constructible
279 static constexpr bool value = std::is_convertible<U, T>::value;
281 template <class T> struct _is_implicitly_constructible<T, void>
283 static constexpr bool value = false;
285 template <> struct _is_implicitly_constructible<void, void>
287 static constexpr bool value = false;
289 template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
291 template <class T, class... Args> struct _is_nothrow_constructible
293 static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value;
295 template <class T> struct _is_nothrow_constructible<T, void>
297 static constexpr bool value = false;
299 template <> struct _is_nothrow_constructible<void, void>
301 static constexpr bool value = false;
303 template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value;
305 template <class T, class... Args> struct _is_constructible
307 static constexpr bool value = std::is_constructible<T, Args...>::value;
309 template <class T> struct _is_constructible<T, void>
311 static constexpr bool value = false;
313 template <> struct _is_constructible<void, void>
315 static constexpr bool value = false;
317 template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value;
319 #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
320 #if defined(_MSC_VER) && _HAS_CXX17
321 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
322 #elif __cplusplus >= 201700
323 // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
325 #if !__has_include(<variant>)
326 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 // must have it if <variant> is present
330 #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
331 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
334 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
338 // True if type is nothrow swappable
339 #if !defined(STANDARDESE_IS_IN_THE_HOUSE) && BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
340 template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
342 template <class T> struct is_nothrow_swappable
344 static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
347 } // namespace detail
348 BOOST_OUTCOME_V2_NAMESPACE_END
350 #ifndef BOOST_OUTCOME_THROW_EXCEPTION
351 #include <boost/throw_exception.hpp>
352 #define BOOST_OUTCOME_THROW_EXCEPTION(expr) BOOST_THROW_EXCEPTION(expr)
355 #ifndef BOOST_OUTCOME_AUTO_TEST_CASE
356 #define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a)