[incrementable.traits] (original) (raw)

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 type

iter_difference_t

be defined as the incrementable type's difference type.

namespace std { template struct incrementable_traits { };

template requires is_object_v struct incrementable_traits<T*> { using difference_type = ptrdiff_t; };

template struct incrementable_traits : incrementable_traits { };

template requires requires { typename T::difference_type; } struct incrementable_traits { using difference_type = typename T::difference_type; };

template requires (!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())>; };

template using iter_difference_t = see below; }

Let be remove_­cvref_­t<I>.

The type iter_­difference_­t<I> denotes

Users may specialize incrementable_­traits on program-defined types.