ranges: add a simplistic implementation of enumerate

This is a temporary workaround because clang lacks it.
This commit is contained in:
Danny Robson 2024-10-17 09:08:19 +10:00
parent ec2f801357
commit ffa09a50a0
2 changed files with 20 additions and 0 deletions

View File

@ -545,6 +545,7 @@ list (
range.cpp
range.hpp
ranges/chunk.hpp
ranges/enumerate.hpp
rational.cpp
rational.hpp
region.cpp

View File

@ -0,0 +1,19 @@
#pragma once
#include <ranges>
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 <typename Rng>
requires (std::ranges::input_range<Rng>)
auto
enumerate (Rng &&r)
{
return std::views::zip (
std::views::iota (0),
std::forward<Rng> (r)
);
}
}