-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathconfig.hpp
More file actions
299 lines (271 loc) · 9.78 KB
/
config.hpp
File metadata and controls
299 lines (271 loc) · 9.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
// Copyright (c) 2019-2020 Krystian Stasiowski (sdkrystian at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/static_string
//
#ifndef BOOST_STATIC_STRING_CONFIG_HPP
#define BOOST_STATIC_STRING_CONFIG_HPP
// Are we dependent on Boost?
// #define BOOST_STATIC_STRING_STANDALONE
#include <cstdint>
// detect 32/64 bit
#if UINTPTR_MAX == UINT64_MAX
#define BOOST_STATIC_STRING_ARCH 64
#elif UINTPTR_MAX == UINT32_MAX
#define BOOST_STATIC_STRING_ARCH 32
#else
#error Unknown or unsupported architecture, please open an issue
#endif
// Can we have deduction guides?
#if __cpp_deduction_guides >= 201703L
#define BOOST_STATIC_STRING_USE_DEDUCT
#endif
// Include <version> if we can
#ifdef __has_include
#if __has_include(<version>)
#include <version>
#endif
#endif
// Can we use __has_builtin?
#ifdef __has_builtin
#define BOOST_STATIC_STRING_HAS_BUILTIN(arg) __has_builtin(arg)
#else
#define BOOST_STATIC_STRING_HAS_BUILTIN(arg) 0
#endif
// Can we use is_constant_evaluated?
#if __cpp_lib_is_constant_evaluated >= 201811L
#define BOOST_STATIC_STRING_IS_CONST_EVAL std::is_constant_evaluated()
#elif BOOST_STATIC_STRING_HAS_BUILTIN(__builtin_is_constant_evaluated)
#define BOOST_STATIC_STRING_IS_CONST_EVAL __builtin_is_constant_evaluated()
#endif
// Check for an attribute
#if defined(__has_cpp_attribute)
#define BOOST_STATIC_STRING_CHECK_FOR_ATTR(x) __has_cpp_attribute(x)
#elif defined(__has_attribute)
#define BOOST_STATIC_STRING_CHECK_FOR_ATTR(x) __has_attribute(x)
#else
#define BOOST_STATIC_STRING_CHECK_FOR_ATTR(x) 0
#endif
// Decide which attributes we can use
#define BOOST_STATIC_STRING_UNLIKELY
#define BOOST_STATIC_STRING_NODISCARD
#define BOOST_STATIC_STRING_NORETURN
#define BOOST_STATIC_STRING_NO_NORETURN
// unlikely
#if BOOST_STATIC_STRING_CHECK_FOR_ATTR(unlikely)
#undef BOOST_STATIC_STRING_UNLIKELY
#define BOOST_STATIC_STRING_UNLIKELY [[unlikely]]
#endif
// nodiscard
#if BOOST_STATIC_STRING_CHECK_FOR_ATTR(nodiscard)
#undef BOOST_STATIC_STRING_NODISCARD
#define BOOST_STATIC_STRING_NODISCARD [[nodiscard]]
#elif defined(_MSC_VER) && _MSC_VER >= 1700
#undef BOOST_STATIC_STRING_NODISCARD
#define BOOST_STATIC_STRING_NODISCARD _Check_return_
#elif defined(__GNUC__) || defined(__clang__)
#undef BOOST_STATIC_STRING_NODISCARD
#define BOOST_STATIC_STRING_NODISCARD __attribute__((warn_unused_result))
#endif
// noreturn
#if BOOST_STATIC_STRING_CHECK_FOR_ATTR(noreturn)
#undef BOOST_STATIC_STRING_NORETURN
#undef BOOST_STATIC_STRING_NO_NORETURN
#define BOOST_STATIC_STRING_NORETURN [[noreturn]]
#elif defined(_MSC_VER)
#undef BOOST_STATIC_STRING_NORETURN
#undef BOOST_STATIC_STRING_NO_NORETURN
#define BOOST_STATIC_STRING_NORETURN __declspec(noreturn)
#elif defined(__GNUC__) || defined(__clang__)
#undef BOOST_STATIC_STRING_NORETURN
#undef BOOST_STATIC_STRING_NO_NORETURN
#define BOOST_STATIC_STRING_NORETURN __attribute__((__noreturn__))
#endif
// _MSVC_LANG isn't avaliable until after VS2015
#if defined(_MSC_VER) && _MSC_VER < 1910L
// The constexpr support in this version is effectively that of
// c++11, so we treat it as such
#define BOOST_STATIC_STRING_STANDARD_VERSION 201103L
#elif defined(_MSVC_LANG)
// MSVC doesn't define __cplusplus by default
#define BOOST_STATIC_STRING_STANDARD_VERSION _MSVC_LANG
#else
#define BOOST_STATIC_STRING_STANDARD_VERSION __cplusplus
#endif
// Decide what level of constexpr we can use
#define BOOST_STATIC_STRING_CPP20_CONSTEXPR
#define BOOST_STATIC_STRING_CPP17_CONSTEXPR
#define BOOST_STATIC_STRING_CPP14_CONSTEXPR
#define BOOST_STATIC_STRING_CPP11_CONSTEXPR
#if BOOST_STATIC_STRING_STANDARD_VERSION >= 202002L
#define BOOST_STATIC_STRING_CPP20
#undef BOOST_STATIC_STRING_CPP20_CONSTEXPR
#define BOOST_STATIC_STRING_CPP20_CONSTEXPR constexpr
#endif
#if BOOST_STATIC_STRING_STANDARD_VERSION >= 201703L
#define BOOST_STATIC_STRING_CPP17
#undef BOOST_STATIC_STRING_CPP17_CONSTEXPR
#define BOOST_STATIC_STRING_CPP17_CONSTEXPR constexpr
#endif
#if BOOST_STATIC_STRING_STANDARD_VERSION >= 201402L
#define BOOST_STATIC_STRING_CPP14
#undef BOOST_STATIC_STRING_CPP14_CONSTEXPR
#define BOOST_STATIC_STRING_CPP14_CONSTEXPR constexpr
#endif
#if BOOST_STATIC_STRING_STANDARD_VERSION >= 201103L
#define BOOST_STATIC_STRING_CPP11
#undef BOOST_STATIC_STRING_CPP11_CONSTEXPR
#define BOOST_STATIC_STRING_CPP11_CONSTEXPR constexpr
#endif
// Boost and non-Boost versions of utilities
#ifndef BOOST_STATIC_STRING_STANDALONE
#ifndef BOOST_STATIC_STRING_THROW
#define BOOST_STATIC_STRING_THROW(ex) BOOST_THROW_EXCEPTION(ex)
#endif
#ifndef BOOST_STATIC_STRING_ASSERT
#define BOOST_STATIC_STRING_ASSERT(cond) BOOST_ASSERT(cond)
#endif
#else
#ifndef BOOST_STATIC_STRING_THROW
#define BOOST_STATIC_STRING_THROW(ex) throw ex
#endif
#ifndef BOOST_STATIC_STRING_ASSERT
#define BOOST_STATIC_STRING_ASSERT(cond) assert(cond)
#endif
#endif
#ifndef BOOST_STATIC_STRING_STANDALONE
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/container_hash/hash.hpp>
#include <boost/utility/string_view.hpp>
#include <boost/core/detail/string_view.hpp>
#include <boost/throw_exception.hpp>
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) || \
defined(BOOST_STATIC_STRING_CXX17_STRING_VIEW)
#include <string_view>
#define BOOST_STATIC_STRING_HAS_STD_STRING_VIEW
#endif
#else
#include <cassert>
#include <stdexcept>
#if defined(__has_include)
# if !__has_include(<string_view>)
# define BOOST_STATIC_STRING_NO_CXX17_HDR_STRING_VIEW
# endif
/*
* Replicate the logic from Boost.Config
*/
// GNU libstdc++3:
#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
# if ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 70100) || (__cplusplus <= 201402L)
# define BOOST_STATIC_STRING_NO_CXX17_HDR_STRING_VIEW
# endif
// libc++:
#elif defined(_LIBCPP_VERSION)
# if (_LIBCPP_VERSION < 4000) || (__cplusplus <= 201402L)
# define BOOST_STATIC_STRING_NO_CXX17_HDR_STRING_VIEW
# endif
// MSVC uses logic from catch all for BOOST_NO_CXX17_HDR_STRING_VIEW
// catch all:
#elif !defined(_YVALS) && !defined(_CPPLIB_VER)
# if (!defined(__has_include) || (__cplusplus < 201700))
# define BOOST_STATIC_STRING_NO_CXX17_HDR_STRING_VIEW
# elif !__has_include(<string_view>)
# define BOOST_STATIC_STRING_NO_CXX17_HDR_STRING_VIEW
# endif
#endif
#if !defined(BOOST_STATIC_STRING_NO_CXX17_HDR_STRING_VIEW) || \
defined(BOOST_STATIC_STRING_CXX17_STRING_VIEW)
#include <string_view>
#define BOOST_STATIC_STRING_HAS_STD_STRING_VIEW
#endif
#endif
// Compiler bug prevents constexpr from working with clang 4.x and 5.x
// if it is detected, we disable constexpr.
#if (BOOST_STATIC_STRING_STANDARD_VERSION >= 201402L && \
BOOST_STATIC_STRING_STANDARD_VERSION < 201703L) && \
defined(__clang__) && \
((__clang_major__ == 4) || (__clang_major__ == 5))
// This directive works on clang
#warning "C++14 constexpr is not supported in clang 4.x and 5.x due to a compiler bug."
#ifdef BOOST_STATIC_STRING_CPP14
#undef BOOST_STATIC_STRING_CPP14
#endif
#undef BOOST_STATIC_STRING_CPP14_CONSTEXPR
#define BOOST_STATIC_STRING_CPP14_CONSTEXPR
#endif
// This is for compiler/library configurations
// that cannot use the library comparison function
// objects at all in constant expresssions. In these
// cases, we use whatever will make more constexpr work.
#if defined(__clang__) && \
(defined(__GLIBCXX__) || defined(_MSC_VER))
#define BOOST_STATIC_STRING_NO_PTR_COMP_FUNCTIONS
#endif
// In gcc-5, we cannot use throw expressions in a
// constexpr function. However, we have a workaround
// for this using constructors. Also, non-static member
// functions that return the class they are a member of
// causes an ICE during constant evaluation.
#if defined(__GNUC__) && (__GNUC__== 5) && \
defined(BOOST_STATIC_STRING_CPP14)
#define BOOST_STATIC_STRING_GCC5_BAD_CONSTEXPR
#endif
#ifndef BOOST_STATIC_STRING_STANDALONE
#if ! defined(BOOST_NO_CWCHAR) && ! defined(BOOST_NO_SWPRINTF)
#define BOOST_STATIC_STRING_HAS_WCHAR
#endif
#else
#ifndef __has_include
// If we don't have __has_include in standalone,
// we will assume that <cwchar> exists.
#define BOOST_STATIC_STRING_HAS_WCHAR
#elif __has_include(<cwchar>)
#define BOOST_STATIC_STRING_HAS_WCHAR
#endif
#endif
#ifdef BOOST_STATIC_STRING_HAS_WCHAR
#include <cwchar>
#endif
// Define the basic string_view type used by the library
// Conversions to and from other available string_view types
// are still defined.
#if !defined(BOOST_STATIC_STRING_STANDALONE) || \
defined(BOOST_STATIC_STRING_HAS_STD_STRING_VIEW)
#define BOOST_STATIC_STRING_HAS_ANY_STRING_VIEW
namespace boost {
namespace static_strings {
/// The type of `basic_string_view` used by the library
template<typename CharT, typename Traits>
using basic_string_view =
#ifndef BOOST_STATIC_STRING_STANDALONE
boost::basic_string_view<CharT, Traits>;
#else
std::basic_string_view<CharT, Traits>;
#endif
} // static_strings
} // boost
#endif
#if defined(__cpp_lib_to_string) && __cpp_lib_to_string >= 202306L // std::to_[w]string() redefined in terms of std::format()
#define BOOST_STATIC_STRING_USE_STD_FORMAT
#endif
#if defined(__GNUC__) && (__GNUC__ >= 5) && (__GNUC__ <= 10) && !defined(__clang__)
// Workaround for GCC complaining about nested classes being private.
#define BOOST_STATIC_STRING_GCC_NESTED_CLASS_WORKAROUND public:
#else
#define BOOST_STATIC_STRING_GCC_NESTED_CLASS_WORKAROUND
#endif
// GCC 9 incorrectly rejects the pointer equality comparison in
// ptr_in_range() in constant expressions. GCC 10 and later handle
// it correctly.
//
// Clang 3.7 and 9-19 have the same issue.
#if (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ == 9)) \
|| (defined(__clang__) && ((__clang_major__ == 3 && __clang_minor__ == 7) || ((__clang_major__ >= 9) && (__clang_major__ <= 19))))
#define BOOST_STATIC_STRING_CONSTEXPR_PTR_CMP_BROKEN
#endif
#endif