1/* Configure Boost.Outcome with Boost
2(C) 2015-2024 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
3File Created: August 2015
4
5
6Boost Software License - Version 1.0 - August 17th, 2003
7
8Permission is hereby granted, free of charge, to any person or organization
9obtaining a copy of the software and accompanying documentation covered by
10this license (the "Software") to use, reproduce, display, distribute,
11execute, and transmit the Software, and to prepare derivative works of the
12Software, and to permit third-parties to whom the Software is furnished to
13do so, all subject to the following:
14
15The copyright notices in the Software and this entire statement, including
16the above license grant, this restriction and the following disclaimer,
17must be included in all copies of the Software, in whole or in part, and
18all derivative works of the Software, unless such copies or derivative
19works are solely in the form of machine-executable object code generated by
20a source language processor.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
25SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
26FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
27ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28DEALINGS IN THE SOFTWARE.
29*/
30
31#ifndef BOOST_OUTCOME_V2_CONFIG_HPP
32#define BOOST_OUTCOME_V2_CONFIG_HPP
33
34#include "detail/version.hpp"
35
36// Pull in detection of __MINGW64_VERSION_MAJOR
37#if defined(__MINGW32__) && !defined(DOXYGEN_IS_IN_THE_HOUSE)
38#include <_mingw.h>
39#endif
40
41#include <boost/config.hpp>
42
43#ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
44#error Boost.Outcome needs variadic template support in the compiler
45#endif
46#if defined(BOOST_NO_CXX14_CONSTEXPR) && _MSC_FULL_VER < 191100000
47#error Boost.Outcome needs constexpr (C++ 14) support in the compiler
48#endif
49#ifdef BOOST_NO_CXX14_VARIABLE_TEMPLATES
50#error Boost.Outcome needs variable template support in the compiler
51#endif
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.
54#endif
55
56#ifndef BOOST_OUTCOME_SYMBOL_VISIBLE
57#define BOOST_OUTCOME_SYMBOL_VISIBLE BOOST_SYMBOL_VISIBLE
58#endif
59#ifdef __has_cpp_attribute
60#define BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(attr) __has_cpp_attribute(attr)
61#else
62#define BOOST_OUTCOME_HAS_CPP_ATTRIBUTE(attr) (0)
63#endif
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( \
74 "SAL_name" \
75 "(" \
76 "\"_Must_inspect_result_\"" \
77 "," \
78 "\"\"" \
79 "," \
80 "\"2\"" \
81 ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
82#endif
83#endif
84#ifndef BOOST_OUTCOME_NODISCARD
85#define BOOST_OUTCOME_NODISCARD
86#endif
87#ifndef BOOST_OUTCOME_THREAD_LOCAL
88#ifndef BOOST_NO_CXX11_THREAD_LOCAL
89#define BOOST_OUTCOME_THREAD_LOCAL thread_local
90#else
91#if defined(_MSC_VER)
92#define BOOST_OUTCOME_THREAD_LOCAL __declspec(thread)
93#elif defined(__GNUC__)
94#define BOOST_OUTCOME_THREAD_LOCAL __thread
95#else
96#error Unknown compiler, cannot set BOOST_OUTCOME_THREAD_LOCAL
97#endif
98#endif
99#endif
100// Can't use the QuickCppLib preprocessor metaprogrammed Concepts TS support, so ...
101#ifndef BOOST_OUTCOME_TEMPLATE
102#define BOOST_OUTCOME_TEMPLATE(...) template <__VA_ARGS__
103#endif
104#ifndef BOOST_OUTCOME_TREQUIRES
105#define BOOST_OUTCOME_TREQUIRES(...) , __VA_ARGS__ >
106#endif
107#ifndef BOOST_OUTCOME_TEXPR
108#define BOOST_OUTCOME_TEXPR(...) typename = decltype(__VA_ARGS__)
109#endif
110#ifndef BOOST_OUTCOME_TPRED
111#define BOOST_OUTCOME_TPRED(...) typename = std::enable_if_t<__VA_ARGS__>
112#endif
113#ifndef BOOST_OUTCOME_REQUIRES
114#if defined(__cpp_concepts) && (!defined(_MSC_VER) || _MSC_FULL_VER >= 192400000) // VS 2019 16.3 is broken here
115#define BOOST_OUTCOME_REQUIRES(...) requires(__VA_ARGS__)
116#else
117#define BOOST_OUTCOME_REQUIRES(...)
118#endif
119#endif
120
121#ifndef BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR
122#define BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 220 // the v2.2 Outcome release
123#endif
124
125namespace boost
126{
127#define BOOST_OUTCOME_V2
128 //! The Boost.Outcome namespace
129 namespace outcome_v2
130 {
131 }
132}
133/*! The namespace of this Boost.Outcome v2.
134 */
135#define BOOST_OUTCOME_V2_NAMESPACE boost::outcome_v2
136/*! Expands into the appropriate namespace markup to enter the Boost.Outcome v2 namespace.
137 */
138#define BOOST_OUTCOME_V2_NAMESPACE_BEGIN \
139 namespace boost \
140 { \
141 namespace outcome_v2 \
142 {
143/*! Expands into the appropriate namespace markup to enter the C++ module
144exported Boost.Outcome v2 namespace.
145*/
146#define BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN \
147 namespace boost \
148 { \
149 namespace outcome_v2 \
150 {
151/*! \brief Expands into the appropriate namespace markup to exit the Boost.Outcome v2 namespace.
152\ingroup config
153*/
154#define BOOST_OUTCOME_V2_NAMESPACE_END \
155 } \
156 }
157
158#include <cstdint> // for uint32_t etc
159#include <initializer_list>
160#include <iosfwd> // for future serialisation
161#include <new> // for placement in moves etc
162#include <type_traits>
163
164#ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
165#if defined(_MSC_VER) && _HAS_CXX17
166#define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
167#elif __cplusplus >= 201700
168// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
169#ifdef __has_include
170#if !__has_include(<variant>)
171#define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
172#endif
173#endif
174
175#ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
176#define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1
177#endif
178#else
179#define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0
180#endif
181#endif
182
183#if BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
184#include <utility> // for in_place_type_t
185
186BOOST_OUTCOME_V2_NAMESPACE_BEGIN
187template <class T> using in_place_type_t = std::in_place_type_t<T>;
188using std::in_place_type;
189BOOST_OUTCOME_V2_NAMESPACE_END
190#else
191BOOST_OUTCOME_V2_NAMESPACE_BEGIN
192//! Aliases `std::in_place_type_t<T>` if on C++ 17 or later, else defined locally.
193template <class T> struct in_place_type_t
194{
195 explicit in_place_type_t() = default;
196};
197//! Aliases `std::in_place_type<T>` if on C++ 17 or later, else defined locally.
198template <class T> constexpr in_place_type_t<T> in_place_type{};
199BOOST_OUTCOME_V2_NAMESPACE_END
200#endif
201
202#if defined(BOOST_OUTCOME_USE_STD_ADDRESSOF) && !BOOST_OUTCOME_USE_STD_ADDRESSOF
203#define BOOST_OUTCOME_ADDRESS_OF(...) (&__VA_ARGS__)
204#else
205#include <memory> // for std::addressof
206#define BOOST_OUTCOME_ADDRESS_OF(...) std::addressof(__VA_ARGS__)
207#endif
208
209#ifndef BOOST_OUTCOME_ASSERT
210#include <boost/assert.hpp>
211#define BOOST_OUTCOME_ASSERT(...) BOOST_ASSERT(__VA_ARGS__)
212#endif
213
214#ifndef BOOST_OUTCOME_TRIVIAL_ABI
215#if defined(STANDARDESE_IS_IN_THE_HOUSE) || __clang_major__ >= 7
216//! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
217#define BOOST_OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
218#else
219#define BOOST_OUTCOME_TRIVIAL_ABI
220#endif
221#endif
222
223BOOST_OUTCOME_V2_NAMESPACE_BEGIN
224namespace detail
225{
226 // Test if type is an in_place_type_t
227 template <class T> struct is_in_place_type_t
228 {
229 static constexpr bool value = false;
230 };
231 template <class U> struct is_in_place_type_t<in_place_type_t<U>>
232 {
233 static constexpr bool value = true;
234 };
235
236 // Replace void with constructible void_type
237 struct empty_type
238 {
239 };
240 struct void_type
241 {
242 // We always compare true to another instance of me
243 constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
244 constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
245 };
246 template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
247
248 template <class Output, class Input> using rebind_type5 = Output;
249 template <class Output, class Input>
250 using rebind_type4 = std::conditional_t< //
251 std::is_volatile<Input>::value, //
252 std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
253 rebind_type5<Output, Input>>;
254 template <class Output, class Input>
255 using rebind_type3 = std::conditional_t< //
256 std::is_const<Input>::value, //
257 std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
258 rebind_type4<Output, Input>>;
259 template <class Output, class Input>
260 using rebind_type2 = std::conditional_t< //
261 std::is_lvalue_reference<Input>::value, //
262 std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
263 rebind_type3<Output, Input>>;
264 template <class Output, class Input>
265 using rebind_type = std::conditional_t< //
266 std::is_rvalue_reference<Input>::value, //
267 std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
268 rebind_type2<Output, Input>>;
269
270 // static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
271
272
273 /* True if type is the same or constructible. Works around a bug where clang + libstdc++
274 pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
275 */
276 template <class T, class U> struct _is_explicitly_constructible
277 {
278 static constexpr bool value = std::is_constructible<T, U>::value;
279 };
280 template <class T> struct _is_explicitly_constructible<T, void>
281 {
282 static constexpr bool value = false;
283 };
284 template <> struct _is_explicitly_constructible<void, void>
285 {
286 static constexpr bool value = false;
287 };
288 template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
289
290 template <class T, class U> struct _is_implicitly_constructible
291 {
292 static constexpr bool value = std::is_convertible<U, T>::value;
293 };
294 template <class T> struct _is_implicitly_constructible<T, void>
295 {
296 static constexpr bool value = false;
297 };
298 template <> struct _is_implicitly_constructible<void, void>
299 {
300 static constexpr bool value = false;
301 };
302 template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
303
304 template <class T, class... Args> struct _is_nothrow_constructible
305 {
306 static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value;
307 };
308 template <class T> struct _is_nothrow_constructible<T, void>
309 {
310 static constexpr bool value = false;
311 };
312 template <> struct _is_nothrow_constructible<void, void>
313 {
314 static constexpr bool value = false;
315 };
316 template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value;
317
318 template <class T, class... Args> struct _is_constructible
319 {
320 static constexpr bool value = std::is_constructible<T, Args...>::value;
321 };
322 template <class T> struct _is_constructible<T, void>
323 {
324 static constexpr bool value = false;
325 };
326 template <> struct _is_constructible<void, void>
327 {
328 static constexpr bool value = false;
329 };
330 template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value;
331
332#ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
333#if defined(_MSC_VER) && _HAS_CXX17
334#define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
335#elif __cplusplus >= 201700
336// libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
337#ifdef __has_include
338#if !__has_include(<variant>)
339#define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 // must have it if <variant> is present
340#endif
341#endif
342
343#ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
344#define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
345#endif
346#else
347#define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
348#endif
349#endif
350
351// True if type is nothrow swappable
352#if !defined(STANDARDESE_IS_IN_THE_HOUSE) && BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
353 template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
354#else
355 template <class T> struct is_nothrow_swappable
356 {
357 static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
358 };
359#endif
360} // namespace detail
361BOOST_OUTCOME_V2_NAMESPACE_END
362
363#ifndef BOOST_OUTCOME_THROW_EXCEPTION
364#include <boost/throw_exception.hpp>
365#define BOOST_OUTCOME_THROW_EXCEPTION(expr) BOOST_THROW_EXCEPTION(expr)
366#endif
367
368#ifndef BOOST_OUTCOME_AUTO_TEST_CASE
369#define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a)
370#endif
371
372#endif
373

source code of boost/libs/outcome/include/boost/outcome/config.hpp