operator-(std::counted_iterator<I>, std::default_sentinel_t)
From cppreference.com
< cpp | iterator | counted iterator
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Iterator library
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)(C++23)(C++20)(C++20)
(deprecated in C++17)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++14)
(C++11)
(C++11)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++23)
(C++23)
(C++23)
(C++23)
(C++23)
(C++11)(C++14)
(C++14)(C++14)
std::counted_iterator
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
operator-(default_sentinel_t)
(C++20)
(C++20)
(C++20)
friend constexpr std::iter_difference_t <I> operator-(
const counted_iterator& x, std::default_sentinel_t );
(1)
(since C++20)
const counted_iterator& x, std::default_sentinel_t );
friend constexpr std::iter_difference_t <I> operator-(
std::default_sentinel_t, const counted_iterator& y );
(2)
(since C++20)
std::default_sentinel_t, const counted_iterator& y );
1) Returns the negative distance to the end.
2) Returns the positive distance to the end.
This function template is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::counted_iterator<I> is an associated class of the arguments.
Contents
[edit] Parameters
x, y
-
iterator adaptors to compute the difference of
[edit] Return value
1) -x.count()
2) y.count()
[edit] Example
Run this code
#include <initializer_list> #include <iterator> int main() { constexpr static auto v = {1, 2, 3, 4}; constexpr std::counted_iterator <std::initializer_list <int>::iterator> it{v.begin(), 3}; constexpr auto d1 = it - std::default_sentinel ; static_assert(d1 == -3); // (1) constexpr auto d2 = std::default_sentinel - it; static_assert(d2 == +3); // (2) }