9 Iterators library [iterators]

9.3 Iterator requirements [iterator.requirements]

9.3.3 Iterator associated types [iterator.assoc.types]

9.3.3.3 iterator_category [iterator.assoc.types.iterator_category]

iterator_category_t<T> is implemented as if:

  template <class> struct iterator_category { };

  template <class T>
  struct iterator_category<T*>
    : enable_if<is_object<T>::value, random_access_iterator_tag> { };

  template <class T>
  struct iterator_category<T const> : iterator_category<T> { };

  template <class T>
    requires requires { typename T::iterator_category; }
  struct iterator_category<T> {
    using type = see below;
  };

  template <class T> using iterator_category_t
    = typename iterator_category<T>::type;

Users may specialize iterator_category on user-defined types.

If T::iterator_category is valid and denotes a type, then the type iterator_category<T>::type is computed as follows:

  • If T::iterator_category is the same as or derives from std::random_access_iterator_tag, iterator_category<T>::type is ranges::random_access_iterator_tag.

  • Otherwise, if T::iterator_category is the same as or derives from std::bidirectional_iterator_tag, iterator_category<T>::type is ranges::bidirectional_iterator_tag.

  • Otherwise, if T::iterator_category is the same as or derives from std::forward_iterator_tag, iterator_category<T>::type is ranges::forward_iterator_tag.

  • Otherwise, if T::iterator_category is the same as or derives from std::input_iterator_tag, iterator_category<T>::type is ranges::input_iterator_tag.

  • Otherwise, if T::iterator_category is the same as or derives from std::output_iterator_tag, iterator_category<T> has no nested type.

  • Otherwise, iterator_category<T>::type is T::iterator_category

rvalue_reference_t<T> is implemented as if:

template <dereferenceable T> requires see below using rvalue_reference_t = decltype(ranges::iter_move(declval<T&>()));

The expression in the requires clause is equivalent to:

requires(T& t) { { ranges::iter_move(t) } -> auto&&; }