2.5 KiB
[incrementable.traits]
24 Iterators library [iterators]
24.3 Iterator requirements [iterator.requirements]
24.3.2 Associated types [iterator.assoc.types]
24.3.2.1 Incrementable traits [incrementable.traits]
To implement algorithms only in terms of incrementable types, it is often necessary to determine the difference type that corresponds to a particular incrementable type.
Accordingly, it is required that if WI is the name of a type that models theweakly_incrementable concept ([iterator.concept.winc]), the typeiter_difference_t be defined as the incrementable type's difference type.
namespace std {template struct incrementable_traits { }; templaterequires is_object_vstruct incrementable_traits<T*> {using difference_type = ptrdiff_t; }; templatestruct incrementable_traits: incrementable_traits { }; templaterequires requires { typename T::difference_type; }struct incrementable_traits {using difference_type = typename T::difference_type; }; templaterequires (!requires { typename T::difference_type; } &&requires(const T& a, const T& b) { { a - b } -> integral; })struct incrementable_traits {using difference_type = make_signed_t<decltype(declval() - declval())>; }; templateusing iter_difference_t = see below;}
Let RI be remove_cvref_t.
The type iter_difference_t denotes
incrementable_traits::difference_type if iterator_traits names a specialization generated from the primary template, and
iterator_traits::difference_type otherwise.
Users may specialize incrementable_traits on program-defined types.