Concept Subspace :: sus :: iter :: ExactSizeIterator

template <class T, class Item = typename std::remove_cvref_t<T>::Item>
concept ExactSizeIterator
requires
sus::iter::Iterator<T, Item>
requires(const std::remove_cvref_t<T>& t) {
      { t.exact_size_hint() } noexcept -> std::same_as<::sus::num::usize>;
    }

An Iterator that knows its exact length.

Many Iterators don’t know how many times they will iterate, but some do. If an iterator knows how many times it can iterate, providing access to that information can be useful. For example, if you want to iterate backwards, a good start is to know where the end is.

Required methods.

An ExactSizeIterator has one required methods, in addition to those required by Iterator.

  • auto exact_size_hint() -> usize returns the exact size of the iterator. The implementation of Iterator::size_hint() must also return the exact size of the iterator (usually by calling exact_size_hint()).

TODO: Rename exact_size_hint to len?