]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/outcome/config.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / outcome / config.hpp
CommitLineData
92f5a8d4 1/* Configure Boost.Outcome with Boost
f67539c2 2(C) 2015-2020 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
92f5a8d4
TL
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("SAL_name" \
74 "(" \
75 "\"_Must_inspect_result_\"" \
76 "," \
77 "\"\"" \
78 "," \
79 "\"2\"" \
80 ")") __declspec("SAL_begin") __declspec("SAL_post") __declspec("SAL_mustInspect") __declspec("SAL_post") __declspec("SAL_checkReturn") __declspec("SAL_end")
81#endif
82#endif
83#ifndef BOOST_OUTCOME_NODISCARD
84#define BOOST_OUTCOME_NODISCARD
85#endif
86#ifndef BOOST_OUTCOME_THREAD_LOCAL
87#ifndef BOOST_NO_CXX11_THREAD_LOCAL
88#define BOOST_OUTCOME_THREAD_LOCAL thread_local
89#else
90#if defined(_MSC_VER)
91#define BOOST_OUTCOME_THREAD_LOCAL __declspec(thread)
92#elif defined(__GNUC__)
93#define BOOST_OUTCOME_THREAD_LOCAL __thread
94#else
95#error Unknown compiler, cannot set BOOST_OUTCOME_THREAD_LOCAL
96#endif
97#endif
98#endif
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__
102#endif
103#ifndef BOOST_OUTCOME_TREQUIRES
104#define BOOST_OUTCOME_TREQUIRES(...) , __VA_ARGS__ >
105#endif
106#ifndef BOOST_OUTCOME_TEXPR
107#define BOOST_OUTCOME_TEXPR(...) typename = decltype(__VA_ARGS__)
108#endif
109#ifndef BOOST_OUTCOME_TPRED
110#define BOOST_OUTCOME_TPRED(...) typename = std::enable_if_t<__VA_ARGS__>
111#endif
112#ifndef BOOST_OUTCOME_REQUIRES
113#if defined(__cpp_concepts) && (!defined(_MSC_VER) || _MSC_FULL_VER >= 192400000) // VS 2019 16.3 is broken here
f67539c2 114#define BOOST_OUTCOME_REQUIRES(...) requires(__VA_ARGS__)
92f5a8d4
TL
115#else
116#define BOOST_OUTCOME_REQUIRES(...)
117#endif
118#endif
119
20effc67
TL
120#ifndef BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR
121#define BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR 210 // the v2.1 Outcome release
122#endif
123
92f5a8d4
TL
124namespace boost
125{
126#define BOOST_OUTCOME_V2
127 //! The Boost.Outcome namespace
128 namespace outcome_v2
129 {
130 }
131}
132/*! The namespace of this Boost.Outcome v2.
133*/
134#define BOOST_OUTCOME_V2_NAMESPACE boost::outcome_v2
135/*! Expands into the appropriate namespace markup to enter the Boost.Outcome v2 namespace.
136*/
137#define BOOST_OUTCOME_V2_NAMESPACE_BEGIN \
138 namespace boost \
139 { \
140 namespace outcome_v2 \
141 {
142/*! Expands into the appropriate namespace markup to enter the C++ module
143exported Boost.Outcome v2 namespace.
144*/
145#define BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN \
146 namespace boost \
147 { \
148 namespace outcome_v2 \
149 {
150/*! \brief Expands into the appropriate namespace markup to exit the Boost.Outcome v2 namespace.
151\ingroup config
152*/
153#define BOOST_OUTCOME_V2_NAMESPACE_END \
154 } \
155 }
156
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>
162
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
168#ifdef __has_include
169#if !__has_include(<variant>)
170#define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0 // must have it if <variant> is present
171#endif
172#endif
173
174#ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
175#define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1
176#endif
177#else
178#define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0
179#endif
180#endif
181
182#if BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
183#include <utility> // for in_place_type_t
184
185BOOST_OUTCOME_V2_NAMESPACE_BEGIN
186template <class T> using in_place_type_t = std::in_place_type_t<T>;
187using std::in_place_type;
188BOOST_OUTCOME_V2_NAMESPACE_END
189#else
190BOOST_OUTCOME_V2_NAMESPACE_BEGIN
191//! Aliases `std::in_place_type_t<T>` if on C++ 17 or later, else defined locally.
192template <class T> struct in_place_type_t
193{
194 explicit in_place_type_t() = default;
195};
196//! Aliases `std::in_place_type<T>` if on C++ 17 or later, else defined locally.
197template <class T> constexpr in_place_type_t<T> in_place_type{};
198BOOST_OUTCOME_V2_NAMESPACE_END
199#endif
200
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]]
205#else
206#define BOOST_OUTCOME_TRIVIAL_ABI
207#endif
208#endif
209
210BOOST_OUTCOME_V2_NAMESPACE_BEGIN
211namespace detail
212{
213 // Test if type is an in_place_type_t
214 template <class T> struct is_in_place_type_t
215 {
216 static constexpr bool value = false;
217 };
218 template <class U> struct is_in_place_type_t<in_place_type_t<U>>
219 {
220 static constexpr bool value = true;
221 };
222
223 // Replace void with constructible void_type
224 struct empty_type
225 {
226 };
227 struct void_type
228 {
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; }
232 };
233 template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
234
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>>;
256
257 // static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
258
259
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).
262 */
263 template <class T, class U> struct _is_explicitly_constructible
264 {
265 static constexpr bool value = std::is_constructible<T, U>::value;
266 };
267 template <class T> struct _is_explicitly_constructible<T, void>
268 {
269 static constexpr bool value = false;
270 };
271 template <> struct _is_explicitly_constructible<void, void>
272 {
273 static constexpr bool value = false;
274 };
275 template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
276
277 template <class T, class U> struct _is_implicitly_constructible
278 {
279 static constexpr bool value = std::is_convertible<U, T>::value;
280 };
281 template <class T> struct _is_implicitly_constructible<T, void>
282 {
283 static constexpr bool value = false;
284 };
285 template <> struct _is_implicitly_constructible<void, void>
286 {
287 static constexpr bool value = false;
288 };
289 template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
290
20effc67
TL
291 template <class T, class... Args> struct _is_nothrow_constructible
292 {
293 static constexpr bool value = std::is_nothrow_constructible<T, Args...>::value;
294 };
295 template <class T> struct _is_nothrow_constructible<T, void>
296 {
297 static constexpr bool value = false;
298 };
299 template <> struct _is_nothrow_constructible<void, void>
300 {
301 static constexpr bool value = false;
302 };
303 template <class T, class... Args> static constexpr bool is_nothrow_constructible = _is_nothrow_constructible<T, Args...>::value;
304
305 template <class T, class... Args> struct _is_constructible
306 {
307 static constexpr bool value = std::is_constructible<T, Args...>::value;
308 };
309 template <class T> struct _is_constructible<T, void>
310 {
311 static constexpr bool value = false;
312 };
313 template <> struct _is_constructible<void, void>
314 {
315 static constexpr bool value = false;
316 };
317 template <class T, class... Args> static constexpr bool is_constructible = _is_constructible<T, Args...>::value;
318
92f5a8d4
TL
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
324#ifdef __has_include
325#if !__has_include(<variant>)
326#define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0 // must have it if <variant> is present
327#endif
328#endif
329
330#ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
331#define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
332#endif
333#else
334#define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
335#endif
336#endif
337
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>;
341#else
342 template <class T> struct is_nothrow_swappable
343 {
344 static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
345 };
346#endif
347} // namespace detail
348BOOST_OUTCOME_V2_NAMESPACE_END
349
350#ifndef BOOST_OUTCOME_THROW_EXCEPTION
351#include <boost/throw_exception.hpp>
352#define BOOST_OUTCOME_THROW_EXCEPTION(expr) BOOST_THROW_EXCEPTION(expr)
353#endif
354
355#ifndef BOOST_OUTCOME_AUTO_TEST_CASE
356#define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a)
357#endif
358
359#endif