From ffa09a50a07e60e1a9d370993c0709ccb1a22b2d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 17 Oct 2024 09:08:19 +1000 Subject: [PATCH] ranges: add a simplistic implementation of enumerate This is a temporary workaround because clang lacks it. --- cruft/util/CMakeLists.txt | 1 + cruft/util/ranges/enumerate.hpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 cruft/util/ranges/enumerate.hpp diff --git a/cruft/util/CMakeLists.txt b/cruft/util/CMakeLists.txt index 94c8d0a7..e799a912 100644 --- a/cruft/util/CMakeLists.txt +++ b/cruft/util/CMakeLists.txt @@ -545,6 +545,7 @@ list ( range.cpp range.hpp ranges/chunk.hpp + ranges/enumerate.hpp rational.cpp rational.hpp region.cpp diff --git a/cruft/util/ranges/enumerate.hpp b/cruft/util/ranges/enumerate.hpp new file mode 100644 index 00000000..a1b6d58e --- /dev/null +++ b/cruft/util/ranges/enumerate.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace cruft::util::ranges { + /// A very simple implementation of std::views::enumerate provided because clang-19 lacks it + /// + /// clang#19: check me again in clang-20 + template + requires (std::ranges::input_range) + auto + enumerate (Rng &&r) + { + return std::views::zip ( + std::views::iota (0), + std::forward (r) + ); + } +}