1 /* Configure Boost.Outcome with Boost
2 (C) 2015-2019 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(...)
122 #define BOOST_OUTCOME_V2
123 //! The Boost.Outcome namespace
128 /*! The namespace of this Boost.Outcome v2.
130 #define BOOST_OUTCOME_V2_NAMESPACE boost::outcome_v2
131 /*! Expands into the appropriate namespace markup to enter the Boost.Outcome v2 namespace.
133 #define BOOST_OUTCOME_V2_NAMESPACE_BEGIN \
136 namespace outcome_v2 \
138 /*! Expands into the appropriate namespace markup to enter the C++ module
139 exported Boost.Outcome v2 namespace.
141 #define BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN \
144 namespace outcome_v2 \
146 /*! \brief Expands into the appropriate namespace markup to exit the Boost.Outcome v2 namespace.
149 #define BOOST_OUTCOME_V2_NAMESPACE_END \
153 #include <cstdint> // for uint32_t etc
154 #include <initializer_list>
155 #include <iosfwd> // for future serialisation
156 #include <new> // for placement in moves etc
157 #include <type_traits>
159 #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
160 #if defined(_MSC_VER) && _HAS_CXX17
161 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1 // MSVC always has std::in_place_type
162 #elif __cplusplus >= 201700
163 // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
165 #if !__has_include(<variant>)
166 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
170 #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
171 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1
174 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0
178 #if BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
179 #include <utility> // for in_place_type_t
181 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
182 template <class T> using in_place_type_t = std::in_place_type_t<T>;
183 using std::in_place_type;
184 BOOST_OUTCOME_V2_NAMESPACE_END
186 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
187 //! Aliases `std::in_place_type_t<T>` if on C++ 17 or later, else defined locally.
188 template <class T> struct in_place_type_t
190 explicit in_place_type_t() = default;
192 //! Aliases `std::in_place_type<T>` if on C++ 17 or later, else defined locally.
193 template <class T> constexpr in_place_type_t<T> in_place_type{};
194 BOOST_OUTCOME_V2_NAMESPACE_END
197 #ifndef BOOST_OUTCOME_TRIVIAL_ABI
198 #if defined(STANDARDESE_IS_IN_THE_HOUSE) || __clang_major__ >= 7
199 //! Defined to be `[[clang::trivial_abi]]` when on a new enough clang compiler. Usually automatic, can be overriden.
200 #define BOOST_OUTCOME_TRIVIAL_ABI [[clang::trivial_abi]]
202 #define BOOST_OUTCOME_TRIVIAL_ABI
206 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
209 // Test if type is an in_place_type_t
210 template <class T> struct is_in_place_type_t
212 static constexpr bool value = false;
214 template <class U> struct is_in_place_type_t<in_place_type_t<U>>
216 static constexpr bool value = true;
219 // Replace void with constructible void_type
225 // We always compare true to another instance of me
226 constexpr bool operator==(void_type /*unused*/) const noexcept { return true; }
227 constexpr bool operator!=(void_type /*unused*/) const noexcept { return false; }
229 template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
231 template <class Output, class Input> using rebind_type5 = Output;
232 template <class Output, class Input>
233 using rebind_type4 = std::conditional_t< //
234 std::is_volatile<Input>::value, //
235 std::add_volatile_t<rebind_type5<Output, std::remove_volatile_t<Input>>>, //
236 rebind_type5<Output, Input>>;
237 template <class Output, class Input>
238 using rebind_type3 = std::conditional_t< //
239 std::is_const<Input>::value, //
240 std::add_const_t<rebind_type4<Output, std::remove_const_t<Input>>>, //
241 rebind_type4<Output, Input>>;
242 template <class Output, class Input>
243 using rebind_type2 = std::conditional_t< //
244 std::is_lvalue_reference<Input>::value, //
245 std::add_lvalue_reference_t<rebind_type3<Output, std::remove_reference_t<Input>>>, //
246 rebind_type3<Output, Input>>;
247 template <class Output, class Input>
248 using rebind_type = std::conditional_t< //
249 std::is_rvalue_reference<Input>::value, //
250 std::add_rvalue_reference_t<rebind_type2<Output, std::remove_reference_t<Input>>>, //
251 rebind_type2<Output, Input>>;
253 // static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
256 /* True if type is the same or constructible. Works around a bug where clang + libstdc++
257 pukes on std::is_constructible<filesystem::path, void> (this bug is fixed upstream).
259 template <class T, class U> struct _is_explicitly_constructible
261 static constexpr bool value = std::is_constructible<T, U>::value;
263 template <class T> struct _is_explicitly_constructible<T, void>
265 static constexpr bool value = false;
267 template <> struct _is_explicitly_constructible<void, void>
269 static constexpr bool value = false;
271 template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
273 template <class T, class U> struct _is_implicitly_constructible
275 static constexpr bool value = std::is_convertible<U, T>::value;
277 template <class T> struct _is_implicitly_constructible<T, void>
279 static constexpr bool value = false;
281 template <> struct _is_implicitly_constructible<void, void>
283 static constexpr bool value = false;
285 template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
287 #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
288 #if defined(_MSC_VER) && _HAS_CXX17
289 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1 // MSVC always has std::is_nothrow_swappable
290 #elif __cplusplus >= 201700
291 // libstdc++ before GCC 6 doesn't have it, despite claiming C++ 17 support
293 #if !__has_include(<variant>)
294 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 // must have it if <variant> is present
298 #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
299 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
302 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
306 // True if type is nothrow swappable
307 #if !defined(STANDARDESE_IS_IN_THE_HOUSE) && BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
308 template <class T> using is_nothrow_swappable = std::is_nothrow_swappable<T>;
310 template <class T> struct is_nothrow_swappable
312 static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
315 } // namespace detail
316 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)
323 #ifndef BOOST_OUTCOME_AUTO_TEST_CASE
324 #define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a)