tmp/tmpx3porb4o/{from.md → to.md}
RENAMED
|
@@ -3,16 +3,16 @@
|
|
| 3 |
Iterators are a generalization of pointers that allow a C++program to
|
| 4 |
work with different data structures (containers) in a uniform manner. To
|
| 5 |
be able to construct template algorithms that work correctly and
|
| 6 |
efficiently on different types of data structures, the library
|
| 7 |
formalizes not just the interfaces but also the semantics and complexity
|
| 8 |
-
assumptions of iterators.
|
| 9 |
`*i`, resulting in a value of some object type `T`, called the *value
|
| 10 |
-
type* of the iterator.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
the expression `i->m` with the same semantics as `(*i).m`. For every
|
| 15 |
iterator type `X` for which equality is defined, there is a
|
| 16 |
corresponding signed integer type called the *difference type* of the
|
| 17 |
iterator.
|
| 18 |
|
|
@@ -39,33 +39,58 @@ iterators also satisfy all the requirements of forward iterators and can
|
|
| 39 |
be used whenever a forward iterator is specified; Random access
|
| 40 |
iterators also satisfy all the requirements of bidirectional iterators
|
| 41 |
and can be used whenever a bidirectional iterator is specified.
|
| 42 |
|
| 43 |
Iterators that further satisfy the requirements of output iterators are
|
| 44 |
-
called *mutable
|
| 45 |
-
*constant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
Just as a regular pointer to an array guarantees that there is a pointer
|
| 48 |
value pointing past the last element of the array, so for any iterator
|
| 49 |
type there is an iterator value that points past the last element of a
|
| 50 |
corresponding sequence. These values are called *past-the-end* values.
|
| 51 |
Values of an iterator `i` for which the expression `*i` is defined are
|
| 52 |
called *dereferenceable*. The library never assumes that past-the-end
|
| 53 |
values are dereferenceable. Iterators can also have singular values that
|
| 54 |
-
are not associated with any sequence.
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
An iterator `j` is called *reachable* from an iterator `i` if and only
|
| 69 |
if there is a finite sequence of applications of the expression `++i`
|
| 70 |
that makes `i == j`. If `j` is reachable from `i`, they refer to
|
| 71 |
elements of the same sequence.
|
|
@@ -93,9 +118,10 @@ In the following sections, `a` and `b` denote values of type `X` or
|
|
| 93 |
`const X`, `difference_type` and `reference` refer to the types
|
| 94 |
`iterator_traits<X>::difference_type` and
|
| 95 |
`iterator_traits<X>::reference`, respectively, `n` denotes a value of
|
| 96 |
`difference_type`, `u`, `tmp`, and `m` denote identifiers, `r` denotes a
|
| 97 |
value of `X&`, `t` denotes a value of value type `T`, `o` denotes a
|
| 98 |
-
value of some type that is writable to the output iterator.
|
| 99 |
-
|
| 100 |
-
`
|
|
|
|
| 101 |
|
|
|
|
| 3 |
Iterators are a generalization of pointers that allow a C++program to
|
| 4 |
work with different data structures (containers) in a uniform manner. To
|
| 5 |
be able to construct template algorithms that work correctly and
|
| 6 |
efficiently on different types of data structures, the library
|
| 7 |
formalizes not just the interfaces but also the semantics and complexity
|
| 8 |
+
assumptions of iterators. An input iterator `i` supports the expression
|
| 9 |
`*i`, resulting in a value of some object type `T`, called the *value
|
| 10 |
+
type* of the iterator. An output iterator `i` has a non-empty set of
|
| 11 |
+
types that are *writable* to the iterator; for each such type `T`, the
|
| 12 |
+
expression `*i = o` is valid where `o` is a value of type `T`. An
|
| 13 |
+
iterator `i` for which the expression `(*i).m` is well-defined supports
|
| 14 |
the expression `i->m` with the same semantics as `(*i).m`. For every
|
| 15 |
iterator type `X` for which equality is defined, there is a
|
| 16 |
corresponding signed integer type called the *difference type* of the
|
| 17 |
iterator.
|
| 18 |
|
|
|
|
| 39 |
be used whenever a forward iterator is specified; Random access
|
| 40 |
iterators also satisfy all the requirements of bidirectional iterators
|
| 41 |
and can be used whenever a bidirectional iterator is specified.
|
| 42 |
|
| 43 |
Iterators that further satisfy the requirements of output iterators are
|
| 44 |
+
called *mutable iterators*. Nonmutable iterators are referred to as
|
| 45 |
+
*constant iterators*.
|
| 46 |
+
|
| 47 |
+
In addition to the requirements in this subclause, the nested
|
| 48 |
+
*typedef-name*s specified in [[iterator.traits]] shall be provided for
|
| 49 |
+
the iterator type.
|
| 50 |
+
|
| 51 |
+
[*Note 1*: Either the iterator type must provide the *typedef-name*s
|
| 52 |
+
directly (in which case `iterator_traits` pick them up automatically),
|
| 53 |
+
or an `iterator_traits` specialization must provide them. — *end note*]
|
| 54 |
+
|
| 55 |
+
Iterators that further satisfy the requirement that, for integral values
|
| 56 |
+
`n` and dereferenceable iterator values `a` and `(a + n)`, `*(a + n)` is
|
| 57 |
+
equivalent to `*(addressof(*a) + n)`, are called *contiguous iterators*.
|
| 58 |
+
|
| 59 |
+
[*Note 2*: For example, the type “pointer to `int`” is a contiguous
|
| 60 |
+
iterator, but `reverse_iterator<int *>` is not. For a valid iterator
|
| 61 |
+
range [`a`,`b`) with dereferenceable `a`, the corresponding range
|
| 62 |
+
denoted by pointers is [`addressof(*a)`,`addressof(*a) + (b - a)`); `b`
|
| 63 |
+
might not be dereferenceable. — *end note*]
|
| 64 |
|
| 65 |
Just as a regular pointer to an array guarantees that there is a pointer
|
| 66 |
value pointing past the last element of the array, so for any iterator
|
| 67 |
type there is an iterator value that points past the last element of a
|
| 68 |
corresponding sequence. These values are called *past-the-end* values.
|
| 69 |
Values of an iterator `i` for which the expression `*i` is defined are
|
| 70 |
called *dereferenceable*. The library never assumes that past-the-end
|
| 71 |
values are dereferenceable. Iterators can also have singular values that
|
| 72 |
+
are not associated with any sequence.
|
| 73 |
+
|
| 74 |
+
[*Example 1*: After the declaration of an uninitialized pointer `x` (as
|
| 75 |
+
with `int* x;`), `x` must always be assumed to have a singular value of
|
| 76 |
+
a pointer. — *end example*]
|
| 77 |
+
|
| 78 |
+
Results of most expressions are undefined for singular values; the only
|
| 79 |
+
exceptions are destroying an iterator that holds a singular value, the
|
| 80 |
+
assignment of a non-singular value to an iterator that holds a singular
|
| 81 |
+
value, and, for iterators that satisfy the `DefaultConstructible`
|
| 82 |
+
requirements, using a value-initialized iterator as the source of a copy
|
| 83 |
+
or move operation.
|
| 84 |
+
|
| 85 |
+
[*Note 3*: This guarantee is not offered for default-initialization,
|
| 86 |
+
although the distinction only matters for types with trivial default
|
| 87 |
+
constructors such as pointers or aggregates holding
|
| 88 |
+
pointers. — *end note*]
|
| 89 |
+
|
| 90 |
+
In these cases the singular value is overwritten the same way as any
|
| 91 |
+
other value. Dereferenceable values are always non-singular.
|
| 92 |
|
| 93 |
An iterator `j` is called *reachable* from an iterator `i` if and only
|
| 94 |
if there is a finite sequence of applications of the expression `++i`
|
| 95 |
that makes `i == j`. If `j` is reachable from `i`, they refer to
|
| 96 |
elements of the same sequence.
|
|
|
|
| 118 |
`const X`, `difference_type` and `reference` refer to the types
|
| 119 |
`iterator_traits<X>::difference_type` and
|
| 120 |
`iterator_traits<X>::reference`, respectively, `n` denotes a value of
|
| 121 |
`difference_type`, `u`, `tmp`, and `m` denote identifiers, `r` denotes a
|
| 122 |
value of `X&`, `t` denotes a value of value type `T`, `o` denotes a
|
| 123 |
+
value of some type that is writable to the output iterator.
|
| 124 |
+
|
| 125 |
+
[*Note 4*: For an iterator type `X` there must be an instantiation of
|
| 126 |
+
`iterator_traits<X>` ([[iterator.traits]]). — *end note*]
|
| 127 |
|