|
25 | 25 |
|
26 | 26 | #define MLIB_PASTE(A, ...) _mlibPaste1(A, __VA_ARGS__) |
27 | 27 | #define MLIB_PASTE_3(A, B, ...) MLIB_PASTE(A, MLIB_PASTE(B, __VA_ARGS__)) |
28 | | -#define MLIB_PASTE_4(A, B, C, ...) \ |
29 | | - MLIB_PASTE(A, MLIB_PASTE_3(B, C, __VA_ARGS__)) |
30 | | -#define MLIB_PASTE_5(A, B, C, D, ...) \ |
31 | | - MLIB_PASTE(A, MLIB_PASTE_4(B, C, D, __VA_ARGS__)) |
| 28 | +#define MLIB_PASTE_4(A, B, C, ...) MLIB_PASTE(A, MLIB_PASTE_3(B, C, __VA_ARGS__)) |
| 29 | +#define MLIB_PASTE_5(A, B, C, D, ...) MLIB_PASTE(A, MLIB_PASTE_4(B, C, D, __VA_ARGS__)) |
32 | 30 | #define _mlibPaste1(A, ...) A##__VA_ARGS__ |
33 | 31 |
|
34 | 32 | #define MLIB_STR(...) _mlibStr(__VA_ARGS__) |
|
51 | 49 | #define MLIB_EVAL_2(...) MLIB_EVAL_1(MLIB_EVAL_1(__VA_ARGS__)) |
52 | 50 | #define MLIB_EVAL_1(...) __VA_ARGS__ |
53 | 51 |
|
54 | | -#if defined(__cpp_concepts) && __cpp_concepts >= 201907L && \ |
55 | | - defined(__cpp_impl_three_way_comparison) && \ |
56 | | - __cpp_impl_three_way_comparison >= 201907L |
| 52 | +#if defined(__cpp_concepts) && __cpp_concepts >= 201907L \ |
| 53 | + && defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L |
57 | 54 | #define mlib_have_cxx20() 1 |
58 | 55 | #else |
59 | 56 | #define mlib_have_cxx20() 0 |
|
69 | 66 | * @brief Expands to an integer literal corresponding to the number of macro |
70 | 67 | * arguments. Supports up to fifteen arguments. |
71 | 68 | */ |
72 | | -#define MLIB_ARG_COUNT(...) \ |
73 | | - _mlibPickSixteenth(__VA_ARGS__ __VA_OPT__(, ) 15, 14, 13, 12, 11, 10, 9, 8, \ |
74 | | - 7, 6, 5, 4, 3, 2, 1, 0) |
75 | | -#define _mlibPickSixteenth(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \ |
76 | | - _13, _14, _15, _16, ...) \ |
77 | | - _16 |
| 69 | +#define MLIB_ARG_COUNT(...) \ |
| 70 | + _mlibPickSixteenth(__VA_ARGS__ __VA_OPT__(, ) 15, \ |
| 71 | + 14, \ |
| 72 | + 13, \ |
| 73 | + 12, \ |
| 74 | + 11, \ |
| 75 | + 10, \ |
| 76 | + 9, \ |
| 77 | + 8, \ |
| 78 | + 7, \ |
| 79 | + 6, \ |
| 80 | + 5, \ |
| 81 | + 4, \ |
| 82 | + 3, \ |
| 83 | + 2, \ |
| 84 | + 1, \ |
| 85 | + 0) |
| 86 | +#define _mlibPickSixteenth( \ |
| 87 | + _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, ...) \ |
| 88 | + _16 |
78 | 89 |
|
79 | 90 | /** |
80 | 91 | * @brief If the argument expands to `0`, `false`, or nothing, expands to `0`. |
|
93 | 104 | * list. Otherwise, expands to the third argument list. The unused argument list |
94 | 105 | * is not expanded and is discarded. |
95 | 106 | */ |
96 | | -#define MLIB_IF_ELSE(...) \ |
97 | | - MLIB_PASTE(_mlibIfElseBranch_, MLIB_BOOLEAN(__VA_ARGS__)) |
| 107 | +#define MLIB_IF_ELSE(...) MLIB_PASTE(_mlibIfElseBranch_, MLIB_BOOLEAN(__VA_ARGS__)) |
98 | 108 | #define _mlibIfElseBranch_1(...) __VA_ARGS__ _mlibNoExpandNothing |
99 | 109 | #define _mlibIfElseBranch_0(...) MLIB_NOTHING(#__VA_ARGS__) MLIB_JUST |
100 | 110 | #define _mlibNoExpandNothing(...) MLIB_NOTHING(#__VA_ARGS__) |
|
152 | 162 | #define mlib_static_assert MLIB_LANG_PICK(_Static_assert)(static_assert) |
153 | 163 |
|
154 | 164 | #define mlib_extern_c_begin() MLIB_IF_CXX(extern "C" {) mlib_static_assert(1, "") |
155 | | -#define mlib_extern_c_end() MLIB_IF_CXX( \ |
156 | | - }) mlib_static_assert(1, "") |
| 165 | +#define mlib_extern_c_end() MLIB_IF_CXX( \ |
| 166 | + }) mlib_static_assert(1, "") |
157 | 167 |
|
158 | 168 | /** |
159 | 169 | * @brief Use as the prefix of a braced initializer within C headers, allowing |
|
168 | 178 | * @brief (C++ only) Expands to a `static_cast` expression that perfect-forwards |
169 | 179 | * the argument. |
170 | 180 | */ |
171 | | -#define mlib_fwd(...) (static_cast<decltype(__VA_ARGS__) &&>(__VA_ARGS__)) |
| 181 | +#define mlib_fwd(...) (static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)) |
172 | 182 |
|
173 | 183 | #ifdef __has_include |
174 | 184 | #if __has_include(<mlib.tweaks.h>) |
175 | 185 | #include <mlib.tweaks.h> |
176 | | -#endif // __has_include() |
177 | | -#endif // __has_include |
| 186 | +#endif // __has_include() |
| 187 | +#endif // __has_include |
178 | 188 |
|
179 | 189 | #ifndef mlib_audit_allocator_passing |
180 | 190 | /** |
181 | 191 | * @brief Macro that should be used to toggle convenience APIs that will |
182 | 192 | * pass default allocators. |
183 | 193 | */ |
184 | 194 | #define mlib_audit_allocator_passing() 1 |
185 | | -#endif // mlib_audit_allocator_passing |
| 195 | +#endif // mlib_audit_allocator_passing |
186 | 196 |
|
187 | 197 | #ifdef __GNUC__ |
188 | 198 | #define mlib_is_gnu_like() 1 |
|
292 | 302 | #elif __STDC__ == 1 && __STDC_VERSION >= 201112L |
293 | 303 | // Declares C11 support |
294 | 304 | #define mlib_has_generic_selection() 1 |
295 | | -#elif mlib_is_gcc_at_least(4, 9, 0) || mlib_is_clang_at_least(3, 0, 0) || \ |
296 | | - mlib_is_msvc_at_least(19, 28, 0) |
| 305 | +#elif mlib_is_gcc_at_least(4, 9, 0) || mlib_is_clang_at_least(3, 0, 0) \ |
| 306 | + || mlib_is_msvc_at_least(19, 28, 0) |
297 | 307 | // Other compilers that support _Generic() without full C11 |
298 | 308 | #define mlib_has_generic_selection() 1 |
299 | 309 | #else |
300 | 310 | #define mlib_has_generic_selection() 0 |
301 | | -#endif // Check for _Generic() support |
| 311 | +#endif // Check for _Generic() support |
302 | 312 |
|
303 | 313 | /** |
304 | 314 | * @brief Create a generic selection expression with fallback compatibility for |
|
310 | 320 | * @param SelectorExpression The Selector expression for _Generic() |
311 | 321 | * @param __VA_ARGS__ All remaining arguments are the selectors for _Generic() |
312 | 322 | */ |
313 | | -#define mlib_generic(CxxExpression, DefaultExpression, SelectorExpression, \ |
314 | | - ...) \ |
315 | | - MLIB_LANG_PICK(MLIB_IF_ELSE(mlib_has_generic_selection())( \ |
316 | | - _Generic((SelectorExpression), __VA_ARGS__))(DefaultExpression)) \ |
317 | | - (CxxExpression) |
| 323 | +#define mlib_generic(CxxExpression, DefaultExpression, SelectorExpression, ...) \ |
| 324 | + MLIB_LANG_PICK(MLIB_IF_ELSE(mlib_has_generic_selection())( \ |
| 325 | + _Generic((SelectorExpression), __VA_ARGS__))(DefaultExpression)) \ |
| 326 | + (CxxExpression) |
318 | 327 |
|
319 | 328 | /** |
320 | 329 | * @brief For empty struct/union types, this must be the sole non-static |
@@ -348,30 +357,30 @@ namespace mlib { |
348 | 357 | */ |
349 | 358 | mlib_constexpr bool is_constant_evaluated() noexcept { |
350 | 359 | #ifdef __cpp_if_consteval |
351 | | - if consteval { |
352 | | - return true; |
353 | | - } else { |
354 | | - return false; |
355 | | - } |
| 360 | + if consteval { |
| 361 | + return true; |
| 362 | + } else { |
| 363 | + return false; |
| 364 | + } |
356 | 365 | #endif |
357 | 366 | #if mlib_is_gnu_like() || mlib_is_msvc() |
358 | | - // GNU and MSVC share the builtin |
359 | | - return __builtin_is_constant_evaluated(); |
| 367 | + // GNU and MSVC share the builtin |
| 368 | + return __builtin_is_constant_evaluated(); |
360 | 369 | #endif |
361 | | - // Otherwise we cannot check |
362 | | - return false; |
| 370 | + // Otherwise we cannot check |
| 371 | + return false; |
363 | 372 | } |
364 | 373 |
|
365 | 374 | /** |
366 | 375 | * @brief An invocable object that simply returns its argument unchanged |
367 | 376 | */ |
368 | 377 | struct identity { |
369 | | - template <typename T> |
370 | | - mlib_always_inline constexpr T &&operator()(T &&arg) const noexcept { |
371 | | - return static_cast<T &&>(arg); |
372 | | - } |
| 378 | + template <typename T> |
| 379 | + mlib_always_inline constexpr T&& operator()(T&& arg) const noexcept { |
| 380 | + return static_cast<T&&>(arg); |
| 381 | + } |
373 | 382 | }; |
374 | 383 |
|
375 | | -} // namespace mlib |
| 384 | +} // namespace mlib |
376 | 385 |
|
377 | | -#endif // C++ |
| 386 | +#endif // C++ |
0 commit comments