tmp/tmp2ll_7lw_/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### Incrementable traits <a id="incrementable.traits">[[incrementable.traits]]</a>
|
| 2 |
+
|
| 3 |
+
To implement algorithms only in terms of incrementable types, it is
|
| 4 |
+
often necessary to determine the difference type that corresponds to a
|
| 5 |
+
particular incrementable type. Accordingly, it is required that if `WI`
|
| 6 |
+
is the name of a type that models the `weakly_incrementable` concept
|
| 7 |
+
[[iterator.concept.winc]], the type
|
| 8 |
+
|
| 9 |
+
``` cpp
|
| 10 |
+
iter_difference_t<WI>
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
be defined as the incrementable type’s difference type.
|
| 14 |
+
|
| 15 |
+
``` cpp
|
| 16 |
+
namespace std {
|
| 17 |
+
template<class> struct incrementable_traits { };
|
| 18 |
+
|
| 19 |
+
template<class T>
|
| 20 |
+
requires is_object_v<T>
|
| 21 |
+
struct incrementable_traits<T*> {
|
| 22 |
+
using difference_type = ptrdiff_t;
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
template<class I>
|
| 26 |
+
struct incrementable_traits<const I>
|
| 27 |
+
: incrementable_traits<I> { };
|
| 28 |
+
|
| 29 |
+
template<class T>
|
| 30 |
+
requires requires { typename T::difference_type; }
|
| 31 |
+
struct incrementable_traits<T> {
|
| 32 |
+
using difference_type = typename T::difference_type;
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
template<class T>
|
| 36 |
+
requires (!requires { typename T::difference_type; } &&
|
| 37 |
+
requires(const T& a, const T& b) { { a - b } -> integral; })
|
| 38 |
+
struct incrementable_traits<T> {
|
| 39 |
+
using difference_type = make_signed_t<decltype(declval<T>() - declval<T>())>;
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
template<class T>
|
| 43 |
+
using iter_difference_t = see below;
|
| 44 |
+
}
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Let R_`I` be `remove_cvref_t<I>`. The type `iter_difference_t<I>`
|
| 48 |
+
denotes
|
| 49 |
+
|
| 50 |
+
- `incrementable_traits<R_I>::difference_type` if `iterator_traits<R_I>`
|
| 51 |
+
names a specialization generated from the primary template, and
|
| 52 |
+
- `iterator_traits<R_I>::difference_type` otherwise.
|
| 53 |
+
|
| 54 |
+
Users may specialize `incrementable_traits` on program-defined types.
|
| 55 |
+
|