From f0d85acc945ac50912c6044050e375cea18d3883 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sun, 7 Feb 2021 15:24:36 +0330 Subject: [PATCH] AK: Add an iota_array() function that can generate an array ...of increasing values with an optional offset. --- AK/Array.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/AK/Array.h b/AK/Array.h index 6ed6db42a7..ef82eb34ff 100644 --- a/AK/Array.h +++ b/AK/Array.h @@ -84,6 +84,22 @@ struct Array { template Array(T, Types...) -> Array; +namespace Detail { +template +constexpr auto integer_sequence_generate_array([[maybe_unused]] const T offset, IntegerSequence) -> Array +{ + return { { (offset + Is)... } }; +} +} + +template +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(offset, MakeIntegerSequence()); +} + } using AK::Array; +using AK::iota_array;