Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / outcome / config.hpp
1 /* Configure Boost.Outcome with Boost
2 (C) 2015-2019 Niall Douglas <http://www.nedproductions.biz/> (7 commits)
3 File Created: August 2015
4
5
6 Boost Software License - Version 1.0 - August 17th, 2003
7
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:
14
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.
21
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.
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
114 #define BOOST_OUTCOME_REQUIRES(...) requires __VA_ARGS__
115 #else
116 #define BOOST_OUTCOME_REQUIRES(...)
117 #endif
118 #endif
119
120 namespace boost
121 {
122 #define BOOST_OUTCOME_V2
123   //! The Boost.Outcome namespace
124   namespace outcome_v2
125   {
126   }
127 }
128 /*! The namespace of this Boost.Outcome v2.
129 */
130 #define BOOST_OUTCOME_V2_NAMESPACE boost::outcome_v2
131 /*! Expands into the appropriate namespace markup to enter the Boost.Outcome v2 namespace.
132 */
133 #define BOOST_OUTCOME_V2_NAMESPACE_BEGIN                                                                                                                                                                                                                                                                                       \
134   namespace boost                                                                                                                                                                                                                                                                                                              \
135   {                                                                                                                                                                                                                                                                                                                            \
136     namespace outcome_v2                                                                                                                                                                                                                                                                                                       \
137     {
138 /*! Expands into the appropriate namespace markup to enter the C++ module
139 exported Boost.Outcome v2 namespace.
140 */
141 #define BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN                                                                                                                                                                                                                                                                                \
142   namespace boost                                                                                                                                                                                                                                                                                                              \
143   {                                                                                                                                                                                                                                                                                                                            \
144     namespace outcome_v2                                                                                                                                                                                                                                                                                                       \
145     {
146 /*! \brief Expands into the appropriate namespace markup to exit the Boost.Outcome v2 namespace.
147 \ingroup config
148 */
149 #define BOOST_OUTCOME_V2_NAMESPACE_END                                                                                                                                                                                                                                                                                         \
150   }                                                                                                                                                                                                                                                                                                                            \
151   }
152
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>
158
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
164 #ifdef __has_include
165 #if !__has_include(<variant>)
166 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0  // must have it if <variant> is present
167 #endif
168 #endif
169
170 #ifndef BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
171 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 1
172 #endif
173 #else
174 #define BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE 0
175 #endif
176 #endif
177
178 #if BOOST_OUTCOME_USE_STD_IN_PLACE_TYPE
179 #include <utility>  // for in_place_type_t
180
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
185 #else
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
189 {
190   explicit in_place_type_t() = default;
191 };
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
195 #endif
196
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]]
201 #else
202 #define BOOST_OUTCOME_TRIVIAL_ABI
203 #endif
204 #endif
205
206 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
207 namespace detail
208 {
209   // Test if type is an in_place_type_t
210   template <class T> struct is_in_place_type_t
211   {
212     static constexpr bool value = false;
213   };
214   template <class U> struct is_in_place_type_t<in_place_type_t<U>>
215   {
216     static constexpr bool value = true;
217   };
218
219   // Replace void with constructible void_type
220   struct empty_type
221   {
222   };
223   struct void_type
224   {
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; }
228   };
229   template <class T> using devoid = std::conditional_t<std::is_void<T>::value, void_type, T>;
230
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>>;
252
253   // static_assert(std::is_same_v<rebind_type<int, volatile const double &&>, volatile const int &&>, "");
254
255
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).
258   */
259   template <class T, class U> struct _is_explicitly_constructible
260   {
261     static constexpr bool value = std::is_constructible<T, U>::value;
262   };
263   template <class T> struct _is_explicitly_constructible<T, void>
264   {
265     static constexpr bool value = false;
266   };
267   template <> struct _is_explicitly_constructible<void, void>
268   {
269     static constexpr bool value = false;
270   };
271   template <class T, class U> static constexpr bool is_explicitly_constructible = _is_explicitly_constructible<T, U>::value;
272
273   template <class T, class U> struct _is_implicitly_constructible
274   {
275     static constexpr bool value = std::is_convertible<U, T>::value;
276   };
277   template <class T> struct _is_implicitly_constructible<T, void>
278   {
279     static constexpr bool value = false;
280   };
281   template <> struct _is_implicitly_constructible<void, void>
282   {
283     static constexpr bool value = false;
284   };
285   template <class T, class U> static constexpr bool is_implicitly_constructible = _is_implicitly_constructible<T, U>::value;
286
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
292 #ifdef __has_include
293 #if !__has_include(<variant>)
294 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0  // must have it if <variant> is present
295 #endif
296 #endif
297
298 #ifndef BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE
299 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 1
300 #endif
301 #else
302 #define BOOST_OUTCOME_USE_STD_IS_NOTHROW_SWAPPABLE 0
303 #endif
304 #endif
305
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>;
309 #else
310   template <class T> struct is_nothrow_swappable
311   {
312     static constexpr bool value = std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value;
313   };
314 #endif
315 }  // namespace detail
316 BOOST_OUTCOME_V2_NAMESPACE_END
317
318 #ifndef BOOST_OUTCOME_THROW_EXCEPTION
319 #include <boost/throw_exception.hpp>
320 #define BOOST_OUTCOME_THROW_EXCEPTION(expr) BOOST_THROW_EXCEPTION(expr)
321 #endif
322
323 #ifndef BOOST_OUTCOME_AUTO_TEST_CASE
324 #define BOOST_OUTCOME_AUTO_TEST_CASE(a, b) BOOST_AUTO_TEST_CASE(a)
325 #endif
326
327 #endif