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
jh::concepts::is_iterator Concept Reference

Concept for detecting iterator-like types based on behavior. More...

#include <jh/conceptual/iterator.h>

Concept definition

template<typename I>
concept is_iterator =requires(I it) {
*it;
{ ++it } -> std::same_as<I &>;
it++;
} &&
(
(!requires { typename I::difference_type; }) ||
(requires { typename I::difference_type; } &&
!std::same_as<typename I::difference_type, void> &&
std::signed_integral<typename I::difference_type>
)
) &&
(
(!requires { typename I::difference_type; } || !requires(I a, I b) { a - b; }) ||
(requires(I a, I b) {
typename I::difference_type;
{ a - b } -> std::convertible_to<typename I::difference_type>;
}
)
)
Concept for detecting iterator-like types based on behavior.
Definition iterator.h:387

Detailed Description

Concept for detecting iterator-like types based on behavior.

  • Supports basic iteration operations: *it, ++it, and it++.
  • If difference_type is defined, it must be a signed integral type.
  • If both difference_type and operator- are defined, the result of a - b must be convertible to difference_type.
  • difference_type may be omitted, but its definition must not conflict with iterator arithmetic semantics.
Template Parameters
IType to be tested for iterator-like behavior.
Note
Conceptually equivalent to std::input_or_output_iterator but implemented through pure behavioral (duck-typed) validation.