mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add an iota_array() function that can generate an array
...of increasing values with an optional offset.
This commit is contained in:
parent
de947acaf9
commit
f0d85acc94
Notes:
sideshowbarker
2024-07-18 22:30:32 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/f0d85acc945 Pull-request: https://github.com/SerenityOS/serenity/pull/4986 Reviewed-by: https://github.com/BenWiederhake Reviewed-by: https://github.com/asynts
1 changed files with 16 additions and 0 deletions
16
AK/Array.h
16
AK/Array.h
|
@ -84,6 +84,22 @@ struct Array {
|
|||
template<typename T, typename... Types>
|
||||
Array(T, Types...) -> Array<T, sizeof...(Types) + 1>;
|
||||
|
||||
namespace Detail {
|
||||
template<typename T, unsigned long... Is>
|
||||
constexpr auto integer_sequence_generate_array([[maybe_unused]] const T offset, IntegerSequence<T, Is...>) -> Array<T, sizeof...(Is)>
|
||||
{
|
||||
return { { (offset + Is)... } };
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, T N>
|
||||
constexpr static auto iota_array(const T offset = {})
|
||||
{
|
||||
static_assert(N >= T {}, "Negative sizes not allowed in iota_array()");
|
||||
return Detail::integer_sequence_generate_array<T>(offset, MakeIntegerSequence<T, N>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::Array;
|
||||
using AK::iota_array;
|
||||
|
|
Loading…
Reference in a new issue