mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +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
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