|
20 | 20 | /* <mstd_type_traits>
|
21 | 21 | *
|
22 | 22 | * - includes toolchain's <type_traits>
|
23 |
| - * - For ARM C 5, standard C++11/14 features: |
24 |
| - * - std::integral_constant, std::true_type, std::false_type |
25 |
| - * - primary type categories (std::is_void, std::is_integral etc) |
26 |
| - * - composite type categories (std::is_reference etc) |
27 |
| - * - type properties (std::is_const, std::is_constructible etc), except std::is_final |
28 |
| - * - type property queries (std::alignment_of, std::rank, std::extent) |
29 |
| - * - type relations (std::is_same, std::is_base_of, std::is_convertible) |
30 |
| - * - const-volatile modifications (std::remove_cv, std::add_const etc) |
31 |
| - * - reference modifications (std::remove_reference, std::add_lvalue_reference etc) |
32 |
| - * - sign modifications (std::make_signed, std::make_unsigned) |
33 |
| - * - array modifications (std::remove_extent, std::remove_all_extents) |
34 |
| - * - pointer modifications (std::remove_pointer, std::add_pointer) |
35 |
| - * - other modifications: |
36 |
| - * - std::aligned_storage |
37 |
| - * - std::decay |
38 |
| - * - std::enable_if |
39 |
| - * - std::conditional |
40 |
| - * - std::common_type |
41 |
| - * - std::underlying_type |
42 |
| - * - std::result_of |
43 | 23 | * - For all toolchains, C++17/20 backports:
|
44 | 24 | * - mstd::type_identity
|
45 | 25 | * - mstd::bool_constant
|
46 | 26 | * - mstd::void_t
|
47 | 27 | * - mstd::is_invocable, mbed::is_invocable_r, etc
|
48 | 28 | * - mstd::invoke_result
|
49 | 29 | * - logical operator traits (mstd::conjunction, mstd::disjunction, mstd::negation)
|
| 30 | + * - mstd::is_constant_evaluated |
50 | 31 | */
|
51 | 32 |
|
52 | 33 | #include <mstd_cstddef>
|
|
55 | 36 | // The template stuff in here is too confusing for astyle
|
56 | 37 | // *INDENT-OFF*
|
57 | 38 |
|
58 |
| - |
59 | 39 | namespace mstd {
|
60 | 40 |
|
61 | 41 | /* C++20 type identity */
|
@@ -92,6 +72,10 @@ template <typename F, typename... Args>
|
92 | 72 | struct invoke_result;
|
93 | 73 | #endif
|
94 | 74 |
|
| 75 | +} // namespace mstd |
| 76 | + |
| 77 | +namespace mstd { |
| 78 | + |
95 | 79 | using std::is_same;
|
96 | 80 | using std::conditional;
|
97 | 81 | using std::conditional_t;
|
@@ -462,8 +446,30 @@ struct is_nothrow_invocable_r : impl::is_invocable_r<R, invoke_result<F, Args...
|
462 | 446 |
|
463 | 447 | #endif // __cpp_lib_is_invocable
|
464 | 448 |
|
| 449 | +/* C++20 is_constant_evaluated */ |
| 450 | +constexpr bool is_constant_evaluated() noexcept |
| 451 | +{ |
| 452 | +#ifdef __clang__ |
| 453 | +#if __has_builtin(__builtin_is_constant_evaluated) |
| 454 | +#define MSTD_HAS_IS_CONSTANT_EVALUATED 1 |
| 455 | + return __builtin_is_constant_evaluated(); |
| 456 | +#else |
| 457 | + return false; |
| 458 | +#endif |
| 459 | +#elif __GNUC__ >= 9 |
| 460 | +#define MSTD_HAS_IS_CONSTANT_EVALUATED 1 |
| 461 | + return __builtin_is_constant_evaluated(); |
| 462 | +#else |
| 463 | + return false; |
| 464 | +#endif |
| 465 | +} |
465 | 466 |
|
466 |
| -} // namespace mstd |
| 467 | +#if MSTD_HAS_IS_CONSTANT_EVALUATED |
| 468 | +#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED constexpr |
| 469 | +#else |
| 470 | +#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED |
| 471 | +#endif |
467 | 472 |
|
| 473 | +} // namespace mstd |
468 | 474 |
|
469 | 475 | #endif /* MSTD_TYPE_TRAITS_ */
|
0 commit comments