JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
enumerate.h File Reference

jh::ranges::views::enumerate — sequence-aware enumerate adaptor. More...

Go to the source code of this file.

Namespaces

namespace  jh::ranges
 Semantic pipeline namespace for JH range operations.
namespace  jh::ranges::views
 Range view adaptor implementations with explicit semantic control.

Variables

constexpr detail::enumerate_fn jh::ranges::views::enumerate {}
 The user-facing enumerate adaptor.

Detailed Description

jh::ranges::views::enumerate — sequence-aware enumerate adaptor.

Author
JeongHan-Bae <mastropseudo@gmail.com>
See also
jh::ranges::views::zip

This adaptor provides a Python-like enumerate view, implemented via jh::ranges::views::zip and std::views::iota. It pairs each element of a sequence with an increasing index.

Usage (same form as zip):

for (auto [i, v] : enumerate(seq)) { ... } // start from 0
for (auto [i, v] : enumerate(seq, 10)) { ... } // start from 10
for (auto [i, v] : seq | enumerate(5)) { ... } // pipe form
constexpr detail::enumerate_fn enumerate
The user-facing enumerate adaptor.
Definition enumerate.h:149

About index type (diff_t):

  • Deduced via jh::concepts::sequence_difference_t<std::remove_cvref_t<Seq>>.
  • If the associated iterator defines a valid difference_type, or supports subtraction (it - it), that type is used (they must be consistent if both exist).
  • If neither is available, the type falls back to std::ptrdiff_t.
  • Conflicting iterator traits (mismatched difference_type and subtraction result) invalidate the type — such a type does not model jh::concepts::sequence.
  • start is static_cast to diff_t; invalid conversions are ill-formed.
Note
Behavior, composition, and pipeline rules are identical to zip.
Version
1.3.x
Date
2025