1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

AK: Add to_array()

This is useful if you want an array with an explicit type but still
want its size to be inferred.
This commit is contained in:
Nico Weber 2024-02-08 18:52:45 -05:00 committed by Ali Mohammad Pur
parent 10216e1743
commit d84b69ace9
2 changed files with 24 additions and 0 deletions

View file

@ -162,9 +162,24 @@ constexpr auto iota_array(T const offset = {})
return Detail::integer_sequence_generate_array<T>(offset, MakeIntegerSequence<T, N>());
}
namespace Detail {
template<typename T, size_t N, size_t... Is>
constexpr auto to_array_impl(T (&&a)[N], IndexSequence<Is...>) -> Array<T, sizeof...(Is)>
{
return { { a[Is]... } };
}
}
template<typename T, size_t N>
constexpr auto to_array(T (&&a)[N])
{
return Detail::to_array_impl(move(a), MakeIndexSequence<N>());
}
}
#if USING_AK_GLOBALLY
using AK::Array;
using AK::iota_array;
using AK::to_array;
#endif