std::iterator_traits (3) - Linux Manuals
std::iterator_traits: std::iterator_traits
NAME
std::iterator_traits - std::iterator_traits
Synopsis
Defined in header <iterator>
template< class Iter >
struct iterator_traits;
template< class T >
struct iterator_traits<T*>;
template< class T > (until C++20)
struct iterator_traits<const T*>;
std::iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIterator types. This makes it possible to implement algorithms only in terms of iterators.
The class defines the following types:
* difference_type - a signed integer type that can be used to identify distance between iterators
* value_type - the type of the values that can be obtained by dereferencing the iterator. This type is void for output iterators.
* pointer - defines a pointer to the type iterated over (value_type)
* reference - defines a reference to the type iterated over (value_type)
* iterator_category - the category of the iterator. Must be one of iterator_category_tags.
The template can be specialized for user-defined iterators so that the information about the iterator can be retrieved even if the type does not provide the usual typedefs.
User specializations may define the member type iterator_concept to one of iterator_category_tags, to indicate conformance to the iterator concepts. (since C++20)
Template parameters
Iter - the iterator type to retrieve properties for
Member types
Member type Definition
difference_type Iter::difference_type
value_type Iter::value_type
pointer Iter::pointer
reference Iter::reference
iterator_category Iter::iterator_category
If Iter does not have all five member types difference_type, value_type, pointer, reference, and iterator_category, then this template has no members by any of those names (std::iterator_traits is SFINAE-friendly) (since C++17)
If Iter does not have pointer, but has all other four member types, then the member types are declared as follows:
Member type Definition
difference_type Iter::difference_type
value_type Iter::value_type
pointer void
reference Iter::reference
iterator_category Iter::iterator_category
Otherwise, if Iter satisfies the exposition-only concept __LegacyInputIterator, the member types are declared as follows:
Member type Definition
difference_type std::incrementable_traits<Iter>::difference_type
value_type std::readable_traits<Iter>::value_type
pointer Iter::pointer if valid, otherwise decltype(std::declval<Iter&>().operator->()) if valid, otherwise void
reference Iter::reference if valid, otherwise std::iter_reference_t<Iter> (since C++20)
iterator_category otherwise, std::bidirectional_iterator_tag if Iter satisfies __LegacyBidirectionalIterator,