mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +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
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>
|
template<typename T, typename... Types>
|
||||||
Array(T, Types...) -> Array<T, sizeof...(Types) + 1>;
|
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::Array;
|
||||||
|
using AK::iota_array;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue