AK: Add an iota_array() function that can generate an array

...of increasing values with an optional offset.
This commit is contained in:
AnotherTest 2021-02-07 15:24:36 +03:30 committed by Andreas Kling
parent de947acaf9
commit f0d85acc94
Notes: sideshowbarker 2024-07-18 22:30:32 +09:00

View file

@ -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;