mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
AK: Make the constexpr StringView methods actually constexpr
Also add some tests to ensure that they _remain_ constexpr. In general, any runtime assertions, weirdo C casts, pointer aliasing, and such shenanigans should be gated behind the (helpfully newly added) AK::is_constant_evaluated() function when the intention is to write constexpr-capable code. a.k.a. deliver promises of constexpr-ness :P
This commit is contained in:
parent
67d1b28b97
commit
37b0f55104
3 changed files with 41 additions and 4 deletions
|
@ -116,6 +116,15 @@ constexpr decltype(auto) to_underlying(V value) requires(IsEnum<V>)
|
|||
return static_cast<UnderlyingType<V>>(value);
|
||||
}
|
||||
|
||||
constexpr bool is_constant_evaluated()
|
||||
{
|
||||
#if __has_builtin(__builtin_is_constant_evaluated)
|
||||
return __builtin_is_constant_evaluated();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::array_size;
|
||||
|
@ -123,6 +132,7 @@ using AK::ceil_div;
|
|||
using AK::clamp;
|
||||
using AK::exchange;
|
||||
using AK::forward;
|
||||
using AK::is_constant_evaluated;
|
||||
using AK::max;
|
||||
using AK::min;
|
||||
using AK::RawPtr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue