mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add AssertSize utility template to provide rich type size assertions
This type is useful, as the sizes will be visible in the compiler error messages, as they will be part of the template parameters. This is not possible with a normal static_assert of the sizeof a type.
This commit is contained in:
parent
100b3835f0
commit
112de58fe0
Notes:
sideshowbarker
2024-07-18 04:40:26 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/112de58fe06 Pull-request: https://github.com/SerenityOS/serenity/pull/9834 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg
1 changed files with 16 additions and 0 deletions
|
@ -475,6 +475,21 @@ using AddRvalueReference = typename __AddReference<T>::RvalueType;
|
|||
template<class T>
|
||||
requires(IsEnum<T>) using UnderlyingType = __underlying_type(T);
|
||||
|
||||
template<typename T, unsigned ExpectedSize, unsigned ActualSize>
|
||||
struct __AssertSize : TrueType {
|
||||
static_assert(ActualSize == ExpectedSize,
|
||||
"actual size does not match expected size");
|
||||
|
||||
consteval explicit operator bool() const { return value; }
|
||||
};
|
||||
|
||||
// Note: This type is useful, as the sizes will be visible in the
|
||||
// compiler error messages, as they will be part of the
|
||||
// template parameters. This is not possible with a
|
||||
// static_assert on the sizeof a type.
|
||||
template<typename T, unsigned ExpectedSize>
|
||||
using AssertSize = __AssertSize<T, ExpectedSize, sizeof(T)>;
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool IsTrivial = __is_trivial(T);
|
||||
|
||||
|
@ -543,6 +558,7 @@ inline constexpr bool IsSpecializationOf<U<Us...>, U> = true;
|
|||
using AK::Detail::AddConst;
|
||||
using AK::Detail::AddLvalueReference;
|
||||
using AK::Detail::AddRvalueReference;
|
||||
using AK::Detail::AssertSize;
|
||||
using AK::Detail::CommonType;
|
||||
using AK::Detail::Conditional;
|
||||
using AK::Detail::CopyConst;
|
||||
|
|
Loading…
Reference in a new issue