This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
[incrementable.traits]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#incrementable.traits)
### 24.3.2 Associated types [[iterator.assoc.types]](iterator.assoc.types#incrementable.traits)
#### 24.3.2.1 Incrementable traits [incrementable.traits]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L744)
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[.](#1.sentence-1)
Accordingly,
it is required that if WI is the name of a type that models the[weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4Concept weakly_­incrementable[iterator.concept.winc]") concept ([[iterator.concept.winc]](iterator.concept.winc "24.3.4.4Concept weakly_­incrementable")),
the typeiter_difference_t<WI> be defined as the incrementable type's difference type[.](#1.sentence-2)
[🔗](#lib:incrementable_traits)
namespace std {template<class> struct incrementable_traits { }; template<class T>requires is_object_v<T>struct incrementable_traits<T*> {using difference_type = ptrdiff_t; }; template<class I>struct incrementable_traits<const I>: incrementable_traits<I> { }; template<class T>requires requires { typename T::difference_type; }struct incrementable_traits<T> {using difference_type = typename T::difference_type; }; template<class T>requires (!requires { typename T::difference_type; } &&requires(const T& a, const T& b) { { a - b } -> [integral](concepts.arithmetic#concept:integral "18.4.7Arithmetic concepts[concepts.arithmetic]"); })struct incrementable_traits<T> {using difference_type = make_signed_t<decltype(declval<T>() - declval<T>())>; }; template<class T>using iter_difference_t = *see below*;}
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L790)
Let RI be remove_cvref_t<I>[.](#2.sentence-1)
The type iter_difference_t<I> denotes
- [(2.1)](#2.1)
incrementable_traits<RI>::difference_type if iterator_traits<RI> names a specialization
generated from the primary template, and
- [(2.2)](#2.2)
iterator_traits<RI>::difference_type otherwise[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L803)
Users may specialize incrementable_traits on program-defined types[.](#3.sentence-1)