23 Iterators library [iterators]

23.3 Iterator requirements [iterator.requirements]

23.3.2 Associated types [iterator.assoc.types]

23.3.2.2 Readable traits [readable.traits]

To implement algorithms only in terms of readable types, it is often necessary to determine the value type that corresponds to a particular readable type.
Accordingly, it is required that if R is the name of a type that models the readable concept ([iterator.concept.readable]), the type
iter_value_t<R>
be defined as the readable type's value type.
template<class> struct cond-value-type { };     // exposition only
template<class T>
  requires is_object_v<T>
struct cond-value-type {
  using value_type = remove_cv_t<T>;
};

template<class> struct readable_traits { };

template<class T>
struct readable_traits<T*>
  : cond-value-type<T> { };

template<class I>
  requires is_array_v<I>
struct readable_traits<I> {
  using value_type = remove_cv_t<remove_extent_t<I>>;
};

template<class I>
struct readable_traits<const I>
  : readable_traits<I> { };

template<class T>
  requires requires { typename T::value_type; }
struct readable_traits<T>
  : cond-value-type<typename T::value_type> { };

template<class T>
  requires requires { typename T::element_type; }
struct readable_traits<T>
  : cond-value-type<typename T::element_type> { };

template<class T> using iter_value_t = see below;
The type iter_­value_­t<I> denotes
  • readable_­traits<I>​::​value_­type if iterator_­traits<I> names a specialization generated from the primary template, and
  • iterator_­traits<I>​::​value_­type otherwise.
Class template readable_­traits may be specialized on program-defined types.
Note
:
Some legacy output iterators define a nested type named value_­type that is an alias for void.
These types are not readable and have no associated value types.
— end note
 ]
Note
:
Smart pointers like shared_­ptr<int> are readable and have an associated value type, but a smart pointer like shared_­ptr<void> is not readable and has no associated value type.
— end note
 ]