std::counted_iterator 연산자
std::counted_iterator 연산자 (operator==, <=> 등)
두 std::counted_iterator의 기반 길이(즉 끝까지의 거리)를 비교하는 연산자들이에요. C++20부터 있어요.
출처: cppreference
본문
<iterator> 헤더에 정의돼 있어요.
// (1)
template< std::common_with<I> I2 >
friend constexpr bool operator==(
const counted_iterator& x, const counted_iterator<I2>& y );
// (2)
template< std::common_with<I> I2 >
friend constexpr strong_ordering operator<=>(
const counted_iterator& x, const counted_iterator<I2>& y );
기반 길이(끝까지의 거리)를 비교해요.
-
- 기반 길이가 같은지 확인해요.
-
- 기반 길이를
operator<=>로 비교해요.
- 기반 길이를
x와 y가 같은 시퀀스의 요소를 가리키지 않으면 동작은 정의되지 않아요. 즉 어떤 n이 있어 std::next(x.base(), x.count() + n)와 std::next(y.base(), y.count() + n)가 같은 요소를 가리켜야 해요. <, <=, >, >=, != 연산자는 operator<=>와 operator==로부터 합성돼요. 이 함수 템플릿은 일반적인 비한정·한정 조회로는 보이지 않고, std::counted_iterator가 인자의 연관 클래스일 때 argument-dependent lookup으로만 찾을 수 있어요.
반환값
-
x.count() == y.count()
-
x.count() <=> y.count()