mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
AK: Add a TypeList class for expanded compile-time tools
Also add IndexSequence and associated helpers. The TypeList class can be queried for what type is at a certain index, and there are two helper functions: for_each_type, and for_each_type_zipped. for_each_type will invoke a lambda with a TypeWrapper object for each type in the type list. The original type can be obtained by extracting the ::Type from the type of your generic lambda's one argument. for_each_type_zipped will walk two TypeLists in lockstep and pass a TypeWrapper object for the current index in each list to a generic lambda. The original type from the TypeList can again be extracted via the ::Type of the generic lambda's two parameters.
This commit is contained in:
parent
fe4b44b489
commit
3bf77f01a7
2 changed files with 121 additions and 0 deletions
|
@ -517,6 +517,30 @@ using IsArithmetic = IntegralConstant<bool, IsIntegral<T>::value || IsFloatingPo
|
|||
template<typename T>
|
||||
using IsFundamental = IntegralConstant<bool, IsArithmetic<T>::value || IsVoid<T>::value || IsNullPointer<T>::value>;
|
||||
|
||||
template<typename T, T... Ts>
|
||||
struct IntegerSequence {
|
||||
using Type = T;
|
||||
static constexpr unsigned size() noexcept { return sizeof...(Ts); };
|
||||
};
|
||||
|
||||
template<unsigned... Indices>
|
||||
using IndexSequence = IntegerSequence<unsigned, Indices...>;
|
||||
|
||||
template<typename T, T N, T... Ts>
|
||||
auto make_integer_sequence_impl()
|
||||
{
|
||||
if constexpr (N == 0)
|
||||
return IntegerSequence<T, Ts...> {};
|
||||
else
|
||||
return make_integer_sequence_impl<T, N - 1, N - 1, Ts...>();
|
||||
}
|
||||
|
||||
template<typename T, T N>
|
||||
using MakeIntegerSequence = decltype(make_integer_sequence_impl<T, N>());
|
||||
|
||||
template<unsigned N>
|
||||
using MakeIndexSequence = MakeIntegerSequence<unsigned, N>;
|
||||
|
||||
}
|
||||
|
||||
using AK::AddConst;
|
||||
|
@ -528,6 +552,8 @@ using AK::declval;
|
|||
using AK::DependentFalse;
|
||||
using AK::exchange;
|
||||
using AK::forward;
|
||||
using AK::IndexSequence;
|
||||
using AK::IntegerSequence;
|
||||
using AK::is_trivial;
|
||||
using AK::is_trivially_copyable;
|
||||
using AK::IsArithmetic;
|
||||
|
@ -539,6 +565,8 @@ using AK::IsNullPointer;
|
|||
using AK::IsSame;
|
||||
using AK::IsUnion;
|
||||
using AK::IsVoid;
|
||||
using AK::MakeIndexSequence;
|
||||
using AK::MakeIntegerSequence;
|
||||
using AK::MakeSigned;
|
||||
using AK::MakeUnsigned;
|
||||
using AK::max;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue