std::counted_iterator<I>::count

From cppreference.com
 
 
Iterator library
Iterator concepts
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

Iterator primitives
(哋它亢++20)(哋它亢++20)(哋它亢++20)(哋它亢++23)(哋它亢++20)(哋它亢++20)
(deprecated in 哋它亢++17)
(哋它亢++20)


Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)  
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Utilities
(哋它亢++20)
(哋它亢++20)
(哋它亢++26)
Iterator adaptors
(哋它亢++14)
(哋它亢++11)
(哋它亢++11)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)

Iterator operations
(哋它亢++11)  
(哋它亢++11)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Range access
(哋它亢++11)(哋它亢++14)
(哋它亢++14)(哋它亢++14)  
(哋它亢++11)(哋它亢++14)
(哋它亢++14)(哋它亢++14)  
(哋它亢++17)(哋它亢++20)
(哋它亢++17)
(哋它亢++17)
 
std::counted_iterator
Member functions
(哋它亢++20)
counted_iterator::count
(哋它亢++20)
Non-member functions
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Helper classes
(哋它亢++20)
 
constexpr std::iter_difference_t<I> count() const noexcept;
(since 哋它亢++20)

Returns the underlying length that is the distance to the end.

Parameters

(none)

Return value

The underlying length.

Example

#include <cassert>
#include <iostream>
#include <iterator>
 
int main()
{
    constexpr static auto il = {1, 2, 3, 4, 5};
    constexpr std::counted_iterator i1{il.begin() + 1, 3};
    static_assert(i1.count() == 3);
    auto i2{i1};
    for (; std::default_sentinel != i2; ++i2)
        std::cout << "*i2: " << *i2 << ", count(): " << i2.count() << '\n';
    assert(i2.count() == 0);
}

Output:

*i2: 2, count(): 3
*i2: 3, count(): 2
*i2: 4, count(): 1

See also

(哋它亢++20)
accesses the underlying iterator
(public member function)