tmp/tmpii_1en36/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="insert.iterators.general">[[insert.iterators.general]]</a>
|
| 2 |
+
|
| 3 |
+
To make it possible to deal with insertion in the same way as writing
|
| 4 |
+
into an array, a special kind of iterator adaptors, called *insert
|
| 5 |
+
iterators*, are provided in the library. With regular iterator classes,
|
| 6 |
+
|
| 7 |
+
``` cpp
|
| 8 |
+
while (first != last) *result++ = *first++;
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
causes a range \[`first`, `last`) to be copied into a range starting
|
| 12 |
+
with result. The same code with `result` being an insert iterator will
|
| 13 |
+
insert corresponding elements into the container. This device allows all
|
| 14 |
+
of the copying algorithms in the library to work in the *insert mode*
|
| 15 |
+
instead of the *regular overwrite* mode.
|
| 16 |
+
|
| 17 |
+
An insert iterator is constructed from a container and possibly one of
|
| 18 |
+
its iterators pointing to where insertion takes place if it is neither
|
| 19 |
+
at the beginning nor at the end of the container. Insert iterators meet
|
| 20 |
+
the requirements of output iterators. `operator*` returns the insert
|
| 21 |
+
iterator itself. The assignment `operator=(const T& x)` is defined on
|
| 22 |
+
insert iterators to allow writing into them, it inserts `x` right before
|
| 23 |
+
where the insert iterator is pointing. In other words, an insert
|
| 24 |
+
iterator is like a cursor pointing into the container where the
|
| 25 |
+
insertion takes place. `back_insert_iterator` inserts elements at the
|
| 26 |
+
end of a container, `front_insert_iterator` inserts elements at the
|
| 27 |
+
beginning of a container, and `insert_iterator` inserts elements where
|
| 28 |
+
the iterator points to in a container. `back_inserter`,
|
| 29 |
+
`front_inserter`, and `inserter` are three functions making the insert
|
| 30 |
+
iterators out of a container.
|
| 31 |
+
|