From b2e36f4e0f403aa1af43f32201e73e641db5ddb2 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 29 Oct 2024 14:02:10 +1000 Subject: [PATCH] ranges: add izip helper --- cruft/util/CMakeLists.txt | 1 + cruft/util/ranges/izip.hpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 cruft/util/ranges/izip.hpp diff --git a/cruft/util/CMakeLists.txt b/cruft/util/CMakeLists.txt index e799a912..815a920c 100644 --- a/cruft/util/CMakeLists.txt +++ b/cruft/util/CMakeLists.txt @@ -546,6 +546,7 @@ list ( range.hpp ranges/chunk.hpp ranges/enumerate.hpp + ranges/izip.hpp rational.cpp rational.hpp region.cpp diff --git a/cruft/util/ranges/izip.hpp b/cruft/util/ranges/izip.hpp new file mode 100644 index 00000000..d2a15cf4 --- /dev/null +++ b/cruft/util/ranges/izip.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + + +namespace cruft::ranges { + /// A convenience function that combines enumerate and zip, such that a preceding index element is returned in + // the result tuple. + template <::std::ranges::viewable_range... Rs> + constexpr ::std::ranges::view auto + izip (Rs &&...rs) + { + return ::std::views::zip ( + ::std::views::iota (0), + ::std::forward (rs)... + ); + } +}