- tmp/tmpu9_vh3x3/{from.md → to.md} +137 -62
tmp/tmpu9_vh3x3/{from.md → to.md}
RENAMED
|
@@ -200,11 +200,14 @@ iterator if
|
|
| 200 |
- the expressions in Table [[tab:iterator.forward.requirements]] are
|
| 201 |
valid and have the indicated semantics, and
|
| 202 |
- objects of type `X` offer the multi-pass guarantee, described below.
|
| 203 |
|
| 204 |
The domain of == for forward iterators is that of iterators over the
|
| 205 |
-
same underlying sequence.
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
Two dereferenceable iterators `a` and `b` of type `X` offer the
|
| 208 |
*multi-pass guarantee* if:
|
| 209 |
|
| 210 |
- `a == b` implies `++a == ++b` and
|
|
@@ -306,10 +309,13 @@ namespace std {
|
|
| 306 |
reverse_iterator<Iterator>
|
| 307 |
operator+(
|
| 308 |
typename reverse_iterator<Iterator>::difference_type n,
|
| 309 |
const reverse_iterator<Iterator>& x);
|
| 310 |
|
|
|
|
|
|
|
|
|
|
| 311 |
template <class Container> class back_insert_iterator;
|
| 312 |
template <class Container>
|
| 313 |
back_insert_iterator<Container> back_inserter(Container& x);
|
| 314 |
|
| 315 |
template <class Container> class front_insert_iterator;
|
|
@@ -346,11 +352,11 @@ namespace std {
|
|
| 346 |
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
|
| 347 |
template <class Iterator>
|
| 348 |
move_iterator<Iterator> operator+(
|
| 349 |
typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
|
| 350 |
template <class Iterator>
|
| 351 |
-
move_iterator<Iterator> make_move_iterator(
|
| 352 |
|
| 353 |
// [stream.iterators], stream iterators:
|
| 354 |
template <class T, class charT = char, class traits = char_traits<charT>,
|
| 355 |
class Distance = ptrdiff_t>
|
| 356 |
class istream_iterator;
|
|
@@ -379,12 +385,26 @@ namespace std {
|
|
| 379 |
// [iterator.range], range access:
|
| 380 |
template <class C> auto begin(C& c) -> decltype(c.begin());
|
| 381 |
template <class C> auto begin(const C& c) -> decltype(c.begin());
|
| 382 |
template <class C> auto end(C& c) -> decltype(c.end());
|
| 383 |
template <class C> auto end(const C& c) -> decltype(c.end());
|
| 384 |
-
template <class T, size_t N> T* begin(T (&array)[N]);
|
| 385 |
-
template <class T, size_t N> T* end(T (&array)[N]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
}
|
| 387 |
```
|
| 388 |
|
| 389 |
## Iterator primitives <a id="iterator.primitives">[[iterator.primitives]]</a>
|
| 390 |
|
|
@@ -465,24 +485,10 @@ namespace std {
|
|
| 465 |
typedef random_access_iterator_tag iterator_category;
|
| 466 |
};
|
| 467 |
}
|
| 468 |
```
|
| 469 |
|
| 470 |
-
If there is an additional pointer type ` \xname{far}` such that the
|
| 471 |
-
difference of two ` \xname{far}` is of type `long`, an implementation
|
| 472 |
-
may define
|
| 473 |
-
|
| 474 |
-
``` cpp
|
| 475 |
-
template<class T> struct iterator_traits<T __far*> {
|
| 476 |
-
typedef long difference_type;
|
| 477 |
-
typedef T value_type;
|
| 478 |
-
typedef T __far* pointer;
|
| 479 |
-
typedef T __far& reference;
|
| 480 |
-
typedef random_access_iterator_tag iterator_category;
|
| 481 |
-
};
|
| 482 |
-
```
|
| 483 |
-
|
| 484 |
To implement a generic `reverse` function, a C++program can do the
|
| 485 |
following:
|
| 486 |
|
| 487 |
``` cpp
|
| 488 |
template <class BidirectionalIterator>
|
|
@@ -693,12 +699,10 @@ namespace std {
|
|
| 693 |
reverse_iterator operator- (difference_type n) const;
|
| 694 |
reverse_iterator& operator-=(difference_type n);
|
| 695 |
unspecified operator[](difference_type n) const;
|
| 696 |
protected:
|
| 697 |
Iterator current;
|
| 698 |
-
private:
|
| 699 |
-
Iterator deref_tmp; // exposition only
|
| 700 |
};
|
| 701 |
|
| 702 |
template <class Iterator1, class Iterator2>
|
| 703 |
bool operator==(
|
| 704 |
const reverse_iterator<Iterator1>& x,
|
|
@@ -724,15 +728,18 @@ namespace std {
|
|
| 724 |
const reverse_iterator<Iterator1>& x,
|
| 725 |
const reverse_iterator<Iterator2>& y);
|
| 726 |
template <class Iterator1, class Iterator2>
|
| 727 |
auto operator-(
|
| 728 |
const reverse_iterator<Iterator1>& x,
|
| 729 |
-
const reverse_iterator<Iterator2>& y) -> decltype(y.
|
| 730 |
template <class Iterator>
|
| 731 |
reverse_iterator<Iterator> operator+(
|
| 732 |
typename reverse_iterator<Iterator>::difference_type n,
|
| 733 |
const reverse_iterator<Iterator>& x);
|
|
|
|
|
|
|
|
|
|
| 734 |
}
|
| 735 |
```
|
| 736 |
|
| 737 |
#### `reverse_iterator` requirements <a id="reverse.iter.requirements">[[reverse.iter.requirements]]</a>
|
| 738 |
|
|
@@ -803,27 +810,21 @@ reference operator*() const;
|
|
| 803 |
```
|
| 804 |
|
| 805 |
*Effects:*
|
| 806 |
|
| 807 |
``` cpp
|
| 808 |
-
|
| 809 |
-
--
|
| 810 |
-
return *deref_tmp;
|
| 811 |
```
|
| 812 |
|
| 813 |
-
This operation must use an auxiliary member variable rather than a
|
| 814 |
-
temporary variable to avoid returning a reference that persists beyond
|
| 815 |
-
the lifetime of its associated iterator.
|
| 816 |
-
(See [[iterator.requirements]].)
|
| 817 |
-
|
| 818 |
##### `operator->` <a id="reverse.iter.opref">[[reverse.iter.opref]]</a>
|
| 819 |
|
| 820 |
``` cpp
|
| 821 |
pointer operator->() const;
|
| 822 |
```
|
| 823 |
|
| 824 |
-
*Returns:* `
|
| 825 |
|
| 826 |
##### `operator++` <a id="reverse.iter.op++">[[reverse.iter.op++]]</a>
|
| 827 |
|
| 828 |
``` cpp
|
| 829 |
reverse_iterator& operator++();
|
|
@@ -986,11 +987,11 @@ template <class Iterator1, class Iterator2>
|
|
| 986 |
|
| 987 |
``` cpp
|
| 988 |
template <class Iterator1, class Iterator2>
|
| 989 |
auto operator-(
|
| 990 |
const reverse_iterator<Iterator1>& x,
|
| 991 |
-
const reverse_iterator<Iterator2>& y) -> decltype(y.
|
| 992 |
```
|
| 993 |
|
| 994 |
*Returns:* `y.current - x.current`.
|
| 995 |
|
| 996 |
##### `operator+` <a id="reverse.iter.opsum">[[reverse.iter.opsum]]</a>
|
|
@@ -1002,10 +1003,19 @@ template <class Iterator>
|
|
| 1002 |
const reverse_iterator<Iterator>& x);
|
| 1003 |
```
|
| 1004 |
|
| 1005 |
*Returns:* `reverse_iterator<Iterator> (x.current - n)`.
|
| 1006 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
### Insert iterators <a id="insert.iterators">[[insert.iterators]]</a>
|
| 1008 |
|
| 1009 |
To make it possible to deal with insertion in the same way as writing
|
| 1010 |
into an array, a special kind of iterator adaptors, called *insert
|
| 1011 |
iterators*, are provided in the library. With regular iterator classes,
|
|
@@ -1069,11 +1079,11 @@ namespace std {
|
|
| 1069 |
|
| 1070 |
``` cpp
|
| 1071 |
explicit back_insert_iterator(Container& x);
|
| 1072 |
```
|
| 1073 |
|
| 1074 |
-
*Effects:* Initializes `container` with `
|
| 1075 |
|
| 1076 |
##### `back_insert_iterator::operator=` <a id="back.insert.iter.op=">[[back.insert.iter.op=]]</a>
|
| 1077 |
|
| 1078 |
``` cpp
|
| 1079 |
back_insert_iterator<Container>&
|
|
@@ -1153,11 +1163,11 @@ namespace std {
|
|
| 1153 |
|
| 1154 |
``` cpp
|
| 1155 |
explicit front_insert_iterator(Container& x);
|
| 1156 |
```
|
| 1157 |
|
| 1158 |
-
*Effects:* Initializes `container` with `
|
| 1159 |
|
| 1160 |
##### `front_insert_iterator::operator=` <a id="front.insert.iter.op=">[[front.insert.iter.op=]]</a>
|
| 1161 |
|
| 1162 |
``` cpp
|
| 1163 |
front_insert_iterator<Container>&
|
|
@@ -1238,11 +1248,12 @@ namespace std {
|
|
| 1238 |
|
| 1239 |
``` cpp
|
| 1240 |
insert_iterator(Container& x, typename Container::iterator i);
|
| 1241 |
```
|
| 1242 |
|
| 1243 |
-
*Effects:* Initializes `container` with `
|
|
|
|
| 1244 |
|
| 1245 |
##### `insert_iterator::operator=` <a id="insert.iter.op=">[[insert.iter.op=]]</a>
|
| 1246 |
|
| 1247 |
``` cpp
|
| 1248 |
insert_iterator<Container>&
|
|
@@ -1299,13 +1310,13 @@ template <class Container>
|
|
| 1299 |
*Returns:* `insert_iterator<Container>(x, i)`.
|
| 1300 |
|
| 1301 |
### Move iterators <a id="move.iterators">[[move.iterators]]</a>
|
| 1302 |
|
| 1303 |
Class template `move_iterator` is an iterator adaptor with the same
|
| 1304 |
-
behavior as the underlying iterator except that its
|
| 1305 |
implicitly converts the value returned by the underlying iterator’s
|
| 1306 |
-
|
| 1307 |
be called with move iterators to replace copying with moving.
|
| 1308 |
|
| 1309 |
``` cpp
|
| 1310 |
list<string> s;
|
| 1311 |
// populate the list s
|
|
@@ -1377,11 +1388,11 @@ namespace std {
|
|
| 1377 |
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
|
| 1378 |
template <class Iterator>
|
| 1379 |
move_iterator<Iterator> operator+(
|
| 1380 |
typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
|
| 1381 |
template <class Iterator>
|
| 1382 |
-
move_iterator<Iterator> make_move_iterator(
|
| 1383 |
}
|
| 1384 |
```
|
| 1385 |
|
| 1386 |
#### `move_iterator` requirements <a id="move.iter.requirements">[[move.iter.requirements]]</a>
|
| 1387 |
|
|
@@ -1606,11 +1617,11 @@ template <class Iterator>
|
|
| 1606 |
|
| 1607 |
*Returns:* `x + n`.
|
| 1608 |
|
| 1609 |
``` cpp
|
| 1610 |
template <class Iterator>
|
| 1611 |
-
move_iterator<Iterator> make_move_iterator(
|
| 1612 |
```
|
| 1613 |
|
| 1614 |
*Returns:* `move_iterator<Iterator>(i)`.
|
| 1615 |
|
| 1616 |
## Stream iterators <a id="stream.iterators">[[stream.iterators]]</a>
|
|
@@ -1618,11 +1629,11 @@ move_iterator<Iterator> make_move_iterator(const Iterator& i);
|
|
| 1618 |
To make it possible for algorithmic templates to work directly with
|
| 1619 |
input/output streams, appropriate iterator-like class templates are
|
| 1620 |
provided.
|
| 1621 |
|
| 1622 |
``` cpp
|
| 1623 |
-
|
| 1624 |
istream_iterator<double, char>(),
|
| 1625 |
ostream_iterator<double, char>(cout, "\n"));
|
| 1626 |
```
|
| 1627 |
|
| 1628 |
reads a file containing floating point numbers from `cin`, and prints
|
|
@@ -1809,11 +1820,11 @@ namespace std {
|
|
| 1809 |
ostream_iterator<T,charT,traits>& operator*();
|
| 1810 |
ostream_iterator<T,charT,traits>& operator++();
|
| 1811 |
ostream_iterator<T,charT,traits>& operator++(int);
|
| 1812 |
private:
|
| 1813 |
basic_ostream<charT,traits>* out_stream; // exposition only
|
| 1814 |
-
const charT* delim; // exposition
|
| 1815 |
};
|
| 1816 |
}
|
| 1817 |
```
|
| 1818 |
|
| 1819 |
#### `ostream_iterator` constructors and destructor <a id="ostream.iterator.cons.des">[[ostream.iterator.cons.des]]</a>
|
|
@@ -1853,11 +1864,11 @@ ostream_iterator& operator=(const T& value);
|
|
| 1853 |
|
| 1854 |
``` cpp
|
| 1855 |
*out_stream << value;
|
| 1856 |
if (delim != 0)
|
| 1857 |
*out_stream << delim;
|
| 1858 |
-
return
|
| 1859 |
```
|
| 1860 |
|
| 1861 |
``` cpp
|
| 1862 |
ostream_iterator& operator*();
|
| 1863 |
```
|
|
@@ -1877,17 +1888,17 @@ The class template `istreambuf_iterator` defines an input iterator (
|
|
| 1877 |
[[input.iterators]]) that reads successive *characters* from the
|
| 1878 |
streambuf for which it was constructed. `operator*` provides access to
|
| 1879 |
the current input character, if any. `operator->` may return a proxy.
|
| 1880 |
Each time `operator++` is evaluated, the iterator advances to the next
|
| 1881 |
input character. If the end of stream is reached
|
| 1882 |
-
(streambuf_type::sgetc() returns `traits::eof()`), the iterator
|
| 1883 |
-
equal to the *end-of-stream* iterator value. The default
|
| 1884 |
-
`istreambuf_iterator()` and the constructor
|
| 1885 |
-
both construct an end-of-stream iterator object
|
| 1886 |
-
end-of-range. All specializations of
|
| 1887 |
-
|
| 1888 |
-
trivial destructor.
|
| 1889 |
|
| 1890 |
The result of `operator*()` on an end-of-stream iterator is undefined.
|
| 1891 |
For any other iterator value a `char_type` value is returned. It is
|
| 1892 |
impossible to assign a character via an input iterator.
|
| 1893 |
|
|
@@ -1933,15 +1944,14 @@ namespace std {
|
|
| 1933 |
#### Class template `istreambuf_iterator::proxy` <a id="istreambuf.iterator::proxy">[[istreambuf.iterator::proxy]]</a>
|
| 1934 |
|
| 1935 |
``` cpp
|
| 1936 |
namespace std {
|
| 1937 |
template <class charT, class traits = char_traits<charT> >
|
| 1938 |
-
class istreambuf_iterator<charT, traits>::proxy {
|
| 1939 |
charT keep_;
|
| 1940 |
basic_streambuf<charT,traits>* sbuf_;
|
| 1941 |
-
proxy(charT c,
|
| 1942 |
-
basic_streambuf<charT,traits>* sbuf)
|
| 1943 |
: keep_(c), sbuf_(sbuf) { }
|
| 1944 |
public:
|
| 1945 |
charT operator*() { return keep_; }
|
| 1946 |
};
|
| 1947 |
}
|
|
@@ -1985,28 +1995,28 @@ constructor argument `p`.
|
|
| 1985 |
``` cpp
|
| 1986 |
charT operator*() const
|
| 1987 |
```
|
| 1988 |
|
| 1989 |
*Returns:* The character obtained via the `streambuf` member
|
| 1990 |
-
|
| 1991 |
|
| 1992 |
#### `istreambuf_iterator::operator++` <a id="istreambuf.iterator::op++">[[istreambuf.iterator::op++]]</a>
|
| 1993 |
|
| 1994 |
``` cpp
|
| 1995 |
istreambuf_iterator<charT,traits>&
|
| 1996 |
istreambuf_iterator<charT,traits>::operator++();
|
| 1997 |
```
|
| 1998 |
|
| 1999 |
-
*Effects:*
|
| 2000 |
|
| 2001 |
*Returns:* `*this`.
|
| 2002 |
|
| 2003 |
``` cpp
|
| 2004 |
proxy istreambuf_iterator<charT,traits>::operator++(int);
|
| 2005 |
```
|
| 2006 |
|
| 2007 |
-
*Returns:* `proxy(
|
| 2008 |
|
| 2009 |
#### `istreambuf_iterator::equal` <a id="istreambuf.iterator::equal">[[istreambuf.iterator::equal]]</a>
|
| 2010 |
|
| 2011 |
``` cpp
|
| 2012 |
bool equal(const istreambuf_iterator<charT,traits>& b) const;
|
|
@@ -2073,30 +2083,30 @@ to get a character value out of the output iterator.
|
|
| 2073 |
|
| 2074 |
``` cpp
|
| 2075 |
ostreambuf_iterator(ostream_type& s) noexcept;
|
| 2076 |
```
|
| 2077 |
|
| 2078 |
-
*Requires:* `s.rdbuf()` shall not null pointer.
|
| 2079 |
|
| 2080 |
-
*Effects:* `
|
| 2081 |
|
| 2082 |
``` cpp
|
| 2083 |
ostreambuf_iterator(streambuf_type* s) noexcept;
|
| 2084 |
```
|
| 2085 |
|
| 2086 |
*Requires:* `s` shall not be a null pointer.
|
| 2087 |
|
| 2088 |
-
*Effects:*
|
| 2089 |
|
| 2090 |
#### `ostreambuf_iterator` operations <a id="ostreambuf.iter.ops">[[ostreambuf.iter.ops]]</a>
|
| 2091 |
|
| 2092 |
``` cpp
|
| 2093 |
ostreambuf_iterator<charT,traits>&
|
| 2094 |
operator=(charT c);
|
| 2095 |
```
|
| 2096 |
|
| 2097 |
-
*Effects:* If `failed()` yields `false`, calls
|
| 2098 |
otherwise has no effect.
|
| 2099 |
|
| 2100 |
*Returns:* `*this`.
|
| 2101 |
|
| 2102 |
``` cpp
|
|
@@ -2115,13 +2125,13 @@ ostreambuf_iterator<charT,traits>& operator++(int);
|
|
| 2115 |
``` cpp
|
| 2116 |
bool failed() const noexcept;
|
| 2117 |
```
|
| 2118 |
|
| 2119 |
*Returns:* `true` if in any prior use of member `operator=`, the call to
|
| 2120 |
-
|
| 2121 |
|
| 2122 |
-
##
|
| 2123 |
|
| 2124 |
In addition to being available via inclusion of the `<iterator>` header,
|
| 2125 |
the function templates in [[iterator.range]] are available when any of
|
| 2126 |
the following headers are included: `<array>`, `<deque>`,
|
| 2127 |
`<forward_list>`, `<list>`, `<map>`, `<regex>`, `<set>`, `<string>`,
|
|
@@ -2140,21 +2150,85 @@ template <class C> auto end(const C& c) -> decltype(c.end());
|
|
| 2140 |
```
|
| 2141 |
|
| 2142 |
*Returns:* `c.end()`.
|
| 2143 |
|
| 2144 |
``` cpp
|
| 2145 |
-
template <class T, size_t N> T* begin(T (&array)[N]);
|
| 2146 |
```
|
| 2147 |
|
| 2148 |
*Returns:* `array`.
|
| 2149 |
|
| 2150 |
``` cpp
|
| 2151 |
-
template <class T, size_t N> T* end(T (&array)[N]);
|
| 2152 |
```
|
| 2153 |
|
| 2154 |
*Returns:* `array + N`.
|
| 2155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2156 |
<!-- Link reference definitions -->
|
| 2157 |
[back.insert.iter.cons]: #back.insert.iter.cons
|
| 2158 |
[back.insert.iter.op*]: #back.insert.iter.op*
|
| 2159 |
[back.insert.iter.op++]: #back.insert.iter.op++
|
| 2160 |
[back.insert.iter.op=]: #back.insert.iter.op=
|
|
@@ -2232,10 +2306,11 @@ template <class T, size_t N> T* end(T (&array)[N]);
|
|
| 2232 |
[output.iterators]: #output.iterators
|
| 2233 |
[predef.iterators]: #predef.iterators
|
| 2234 |
[random.access.iterators]: #random.access.iterators
|
| 2235 |
[reverse.iter.cons]: #reverse.iter.cons
|
| 2236 |
[reverse.iter.conv]: #reverse.iter.conv
|
|
|
|
| 2237 |
[reverse.iter.op!=]: #reverse.iter.op!=
|
| 2238 |
[reverse.iter.op+]: #reverse.iter.op+
|
| 2239 |
[reverse.iter.op++]: #reverse.iter.op++
|
| 2240 |
[reverse.iter.op+=]: #reverse.iter.op+=
|
| 2241 |
[reverse.iter.op-]: #reverse.iter.op-
|
|
|
|
| 200 |
- the expressions in Table [[tab:iterator.forward.requirements]] are
|
| 201 |
valid and have the indicated semantics, and
|
| 202 |
- objects of type `X` offer the multi-pass guarantee, described below.
|
| 203 |
|
| 204 |
The domain of == for forward iterators is that of iterators over the
|
| 205 |
+
same underlying sequence. However, value-initialized iterators may be
|
| 206 |
+
compared and shall compare equal to other value-initialized iterators of
|
| 207 |
+
the same type. value initialized iterators behave as if they refer past
|
| 208 |
+
the end of the same empty sequence
|
| 209 |
|
| 210 |
Two dereferenceable iterators `a` and `b` of type `X` offer the
|
| 211 |
*multi-pass guarantee* if:
|
| 212 |
|
| 213 |
- `a == b` implies `++a == ++b` and
|
|
|
|
| 309 |
reverse_iterator<Iterator>
|
| 310 |
operator+(
|
| 311 |
typename reverse_iterator<Iterator>::difference_type n,
|
| 312 |
const reverse_iterator<Iterator>& x);
|
| 313 |
|
| 314 |
+
template <class Iterator>
|
| 315 |
+
reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 316 |
+
|
| 317 |
template <class Container> class back_insert_iterator;
|
| 318 |
template <class Container>
|
| 319 |
back_insert_iterator<Container> back_inserter(Container& x);
|
| 320 |
|
| 321 |
template <class Container> class front_insert_iterator;
|
|
|
|
| 352 |
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
|
| 353 |
template <class Iterator>
|
| 354 |
move_iterator<Iterator> operator+(
|
| 355 |
typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
|
| 356 |
template <class Iterator>
|
| 357 |
+
move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 358 |
|
| 359 |
// [stream.iterators], stream iterators:
|
| 360 |
template <class T, class charT = char, class traits = char_traits<charT>,
|
| 361 |
class Distance = ptrdiff_t>
|
| 362 |
class istream_iterator;
|
|
|
|
| 385 |
// [iterator.range], range access:
|
| 386 |
template <class C> auto begin(C& c) -> decltype(c.begin());
|
| 387 |
template <class C> auto begin(const C& c) -> decltype(c.begin());
|
| 388 |
template <class C> auto end(C& c) -> decltype(c.end());
|
| 389 |
template <class C> auto end(const C& c) -> decltype(c.end());
|
| 390 |
+
template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
|
| 391 |
+
template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
|
| 392 |
+
template <class C> constexpr auto cbegin(const C& c) noexcept(noexcept(std::begin(c)))
|
| 393 |
+
-> decltype(std::begin(c));
|
| 394 |
+
template <class C> constexpr auto cend(const C& c) noexcept(noexcept(std::end(c)))
|
| 395 |
+
-> decltype(std::end(c));
|
| 396 |
+
template <class C> auto rbegin(C& c) -> decltype(c.rbegin());
|
| 397 |
+
template <class C> auto rbegin(const C& c) -> decltype(c.rbegin());
|
| 398 |
+
template <class C> auto rend(C& c) -> decltype(c.rend());
|
| 399 |
+
template <class C> auto rend(const C& c) -> decltype(c.rend());
|
| 400 |
+
template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]);
|
| 401 |
+
template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]);
|
| 402 |
+
template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il);
|
| 403 |
+
template <class E> reverse_iterator<const E*> rend(initializer_list<E> il);
|
| 404 |
+
template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c));
|
| 405 |
+
template <class C> auto crend(const C& c) -> decltype(std::rend(c));
|
| 406 |
}
|
| 407 |
```
|
| 408 |
|
| 409 |
## Iterator primitives <a id="iterator.primitives">[[iterator.primitives]]</a>
|
| 410 |
|
|
|
|
| 485 |
typedef random_access_iterator_tag iterator_category;
|
| 486 |
};
|
| 487 |
}
|
| 488 |
```
|
| 489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
To implement a generic `reverse` function, a C++program can do the
|
| 491 |
following:
|
| 492 |
|
| 493 |
``` cpp
|
| 494 |
template <class BidirectionalIterator>
|
|
|
|
| 699 |
reverse_iterator operator- (difference_type n) const;
|
| 700 |
reverse_iterator& operator-=(difference_type n);
|
| 701 |
unspecified operator[](difference_type n) const;
|
| 702 |
protected:
|
| 703 |
Iterator current;
|
|
|
|
|
|
|
| 704 |
};
|
| 705 |
|
| 706 |
template <class Iterator1, class Iterator2>
|
| 707 |
bool operator==(
|
| 708 |
const reverse_iterator<Iterator1>& x,
|
|
|
|
| 728 |
const reverse_iterator<Iterator1>& x,
|
| 729 |
const reverse_iterator<Iterator2>& y);
|
| 730 |
template <class Iterator1, class Iterator2>
|
| 731 |
auto operator-(
|
| 732 |
const reverse_iterator<Iterator1>& x,
|
| 733 |
+
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 734 |
template <class Iterator>
|
| 735 |
reverse_iterator<Iterator> operator+(
|
| 736 |
typename reverse_iterator<Iterator>::difference_type n,
|
| 737 |
const reverse_iterator<Iterator>& x);
|
| 738 |
+
|
| 739 |
+
template <class Iterator>
|
| 740 |
+
reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 741 |
}
|
| 742 |
```
|
| 743 |
|
| 744 |
#### `reverse_iterator` requirements <a id="reverse.iter.requirements">[[reverse.iter.requirements]]</a>
|
| 745 |
|
|
|
|
| 810 |
```
|
| 811 |
|
| 812 |
*Effects:*
|
| 813 |
|
| 814 |
``` cpp
|
| 815 |
+
Iterator tmp = current;
|
| 816 |
+
return *--tmp;
|
|
|
|
| 817 |
```
|
| 818 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 819 |
##### `operator->` <a id="reverse.iter.opref">[[reverse.iter.opref]]</a>
|
| 820 |
|
| 821 |
``` cpp
|
| 822 |
pointer operator->() const;
|
| 823 |
```
|
| 824 |
|
| 825 |
+
*Returns:* `std::addressof(operator*())`.
|
| 826 |
|
| 827 |
##### `operator++` <a id="reverse.iter.op++">[[reverse.iter.op++]]</a>
|
| 828 |
|
| 829 |
``` cpp
|
| 830 |
reverse_iterator& operator++();
|
|
|
|
| 987 |
|
| 988 |
``` cpp
|
| 989 |
template <class Iterator1, class Iterator2>
|
| 990 |
auto operator-(
|
| 991 |
const reverse_iterator<Iterator1>& x,
|
| 992 |
+
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 993 |
```
|
| 994 |
|
| 995 |
*Returns:* `y.current - x.current`.
|
| 996 |
|
| 997 |
##### `operator+` <a id="reverse.iter.opsum">[[reverse.iter.opsum]]</a>
|
|
|
|
| 1003 |
const reverse_iterator<Iterator>& x);
|
| 1004 |
```
|
| 1005 |
|
| 1006 |
*Returns:* `reverse_iterator<Iterator> (x.current - n)`.
|
| 1007 |
|
| 1008 |
+
##### Non-member function `make_reverse_iterator()` <a id="reverse.iter.make">[[reverse.iter.make]]</a>
|
| 1009 |
+
|
| 1010 |
+
``` cpp
|
| 1011 |
+
template <class Iterator>
|
| 1012 |
+
reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 1013 |
+
```
|
| 1014 |
+
|
| 1015 |
+
*Returns:* `reverse_iterator<Iterator>(i)`.
|
| 1016 |
+
|
| 1017 |
### Insert iterators <a id="insert.iterators">[[insert.iterators]]</a>
|
| 1018 |
|
| 1019 |
To make it possible to deal with insertion in the same way as writing
|
| 1020 |
into an array, a special kind of iterator adaptors, called *insert
|
| 1021 |
iterators*, are provided in the library. With regular iterator classes,
|
|
|
|
| 1079 |
|
| 1080 |
``` cpp
|
| 1081 |
explicit back_insert_iterator(Container& x);
|
| 1082 |
```
|
| 1083 |
|
| 1084 |
+
*Effects:* Initializes `container` with `std::addressof(x)`.
|
| 1085 |
|
| 1086 |
##### `back_insert_iterator::operator=` <a id="back.insert.iter.op=">[[back.insert.iter.op=]]</a>
|
| 1087 |
|
| 1088 |
``` cpp
|
| 1089 |
back_insert_iterator<Container>&
|
|
|
|
| 1163 |
|
| 1164 |
``` cpp
|
| 1165 |
explicit front_insert_iterator(Container& x);
|
| 1166 |
```
|
| 1167 |
|
| 1168 |
+
*Effects:* Initializes `container` with `std::addressof(x)`.
|
| 1169 |
|
| 1170 |
##### `front_insert_iterator::operator=` <a id="front.insert.iter.op=">[[front.insert.iter.op=]]</a>
|
| 1171 |
|
| 1172 |
``` cpp
|
| 1173 |
front_insert_iterator<Container>&
|
|
|
|
| 1248 |
|
| 1249 |
``` cpp
|
| 1250 |
insert_iterator(Container& x, typename Container::iterator i);
|
| 1251 |
```
|
| 1252 |
|
| 1253 |
+
*Effects:* Initializes `container` with `std::addressof(x)` and `iter`
|
| 1254 |
+
with `i`.
|
| 1255 |
|
| 1256 |
##### `insert_iterator::operator=` <a id="insert.iter.op=">[[insert.iter.op=]]</a>
|
| 1257 |
|
| 1258 |
``` cpp
|
| 1259 |
insert_iterator<Container>&
|
|
|
|
| 1310 |
*Returns:* `insert_iterator<Container>(x, i)`.
|
| 1311 |
|
| 1312 |
### Move iterators <a id="move.iterators">[[move.iterators]]</a>
|
| 1313 |
|
| 1314 |
Class template `move_iterator` is an iterator adaptor with the same
|
| 1315 |
+
behavior as the underlying iterator except that its indirection operator
|
| 1316 |
implicitly converts the value returned by the underlying iterator’s
|
| 1317 |
+
indirection operator to an rvalue reference. Some generic algorithms can
|
| 1318 |
be called with move iterators to replace copying with moving.
|
| 1319 |
|
| 1320 |
``` cpp
|
| 1321 |
list<string> s;
|
| 1322 |
// populate the list s
|
|
|
|
| 1388 |
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
|
| 1389 |
template <class Iterator>
|
| 1390 |
move_iterator<Iterator> operator+(
|
| 1391 |
typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
|
| 1392 |
template <class Iterator>
|
| 1393 |
+
move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 1394 |
}
|
| 1395 |
```
|
| 1396 |
|
| 1397 |
#### `move_iterator` requirements <a id="move.iter.requirements">[[move.iter.requirements]]</a>
|
| 1398 |
|
|
|
|
| 1617 |
|
| 1618 |
*Returns:* `x + n`.
|
| 1619 |
|
| 1620 |
``` cpp
|
| 1621 |
template <class Iterator>
|
| 1622 |
+
move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 1623 |
```
|
| 1624 |
|
| 1625 |
*Returns:* `move_iterator<Iterator>(i)`.
|
| 1626 |
|
| 1627 |
## Stream iterators <a id="stream.iterators">[[stream.iterators]]</a>
|
|
|
|
| 1629 |
To make it possible for algorithmic templates to work directly with
|
| 1630 |
input/output streams, appropriate iterator-like class templates are
|
| 1631 |
provided.
|
| 1632 |
|
| 1633 |
``` cpp
|
| 1634 |
+
partial_sum(istream_iterator<double, char>(cin),
|
| 1635 |
istream_iterator<double, char>(),
|
| 1636 |
ostream_iterator<double, char>(cout, "\n"));
|
| 1637 |
```
|
| 1638 |
|
| 1639 |
reads a file containing floating point numbers from `cin`, and prints
|
|
|
|
| 1820 |
ostream_iterator<T,charT,traits>& operator*();
|
| 1821 |
ostream_iterator<T,charT,traits>& operator++();
|
| 1822 |
ostream_iterator<T,charT,traits>& operator++(int);
|
| 1823 |
private:
|
| 1824 |
basic_ostream<charT,traits>* out_stream; // exposition only
|
| 1825 |
+
const charT* delim; // exposition only
|
| 1826 |
};
|
| 1827 |
}
|
| 1828 |
```
|
| 1829 |
|
| 1830 |
#### `ostream_iterator` constructors and destructor <a id="ostream.iterator.cons.des">[[ostream.iterator.cons.des]]</a>
|
|
|
|
| 1864 |
|
| 1865 |
``` cpp
|
| 1866 |
*out_stream << value;
|
| 1867 |
if (delim != 0)
|
| 1868 |
*out_stream << delim;
|
| 1869 |
+
return *this;
|
| 1870 |
```
|
| 1871 |
|
| 1872 |
``` cpp
|
| 1873 |
ostream_iterator& operator*();
|
| 1874 |
```
|
|
|
|
| 1888 |
[[input.iterators]]) that reads successive *characters* from the
|
| 1889 |
streambuf for which it was constructed. `operator*` provides access to
|
| 1890 |
the current input character, if any. `operator->` may return a proxy.
|
| 1891 |
Each time `operator++` is evaluated, the iterator advances to the next
|
| 1892 |
input character. If the end of stream is reached
|
| 1893 |
+
(`streambuf_type::sgetc()` returns `traits::eof()`), the iterator
|
| 1894 |
+
becomes equal to the *end-of-stream* iterator value. The default
|
| 1895 |
+
constructor `istreambuf_iterator()` and the constructor
|
| 1896 |
+
`istreambuf_iterator(0)` both construct an end-of-stream iterator object
|
| 1897 |
+
suitable for use as an end-of-range. All specializations of
|
| 1898 |
+
`istreambuf_iterator` shall have a trivial copy constructor, a
|
| 1899 |
+
`constexpr` default constructor, and a trivial destructor.
|
| 1900 |
|
| 1901 |
The result of `operator*()` on an end-of-stream iterator is undefined.
|
| 1902 |
For any other iterator value a `char_type` value is returned. It is
|
| 1903 |
impossible to assign a character via an input iterator.
|
| 1904 |
|
|
|
|
| 1944 |
#### Class template `istreambuf_iterator::proxy` <a id="istreambuf.iterator::proxy">[[istreambuf.iterator::proxy]]</a>
|
| 1945 |
|
| 1946 |
``` cpp
|
| 1947 |
namespace std {
|
| 1948 |
template <class charT, class traits = char_traits<charT> >
|
| 1949 |
+
class istreambuf_iterator<charT, traits>::proxy { // exposition only
|
| 1950 |
charT keep_;
|
| 1951 |
basic_streambuf<charT,traits>* sbuf_;
|
| 1952 |
+
proxy(charT c, basic_streambuf<charT,traits>* sbuf)
|
|
|
|
| 1953 |
: keep_(c), sbuf_(sbuf) { }
|
| 1954 |
public:
|
| 1955 |
charT operator*() { return keep_; }
|
| 1956 |
};
|
| 1957 |
}
|
|
|
|
| 1995 |
``` cpp
|
| 1996 |
charT operator*() const
|
| 1997 |
```
|
| 1998 |
|
| 1999 |
*Returns:* The character obtained via the `streambuf` member
|
| 2000 |
+
`sbuf_->sgetc()`.
|
| 2001 |
|
| 2002 |
#### `istreambuf_iterator::operator++` <a id="istreambuf.iterator::op++">[[istreambuf.iterator::op++]]</a>
|
| 2003 |
|
| 2004 |
``` cpp
|
| 2005 |
istreambuf_iterator<charT,traits>&
|
| 2006 |
istreambuf_iterator<charT,traits>::operator++();
|
| 2007 |
```
|
| 2008 |
|
| 2009 |
+
*Effects:* `sbuf_->sbumpc()`.
|
| 2010 |
|
| 2011 |
*Returns:* `*this`.
|
| 2012 |
|
| 2013 |
``` cpp
|
| 2014 |
proxy istreambuf_iterator<charT,traits>::operator++(int);
|
| 2015 |
```
|
| 2016 |
|
| 2017 |
+
*Returns:* `proxy(sbuf_->sbumpc(), sbuf_)`.
|
| 2018 |
|
| 2019 |
#### `istreambuf_iterator::equal` <a id="istreambuf.iterator::equal">[[istreambuf.iterator::equal]]</a>
|
| 2020 |
|
| 2021 |
``` cpp
|
| 2022 |
bool equal(const istreambuf_iterator<charT,traits>& b) const;
|
|
|
|
| 2083 |
|
| 2084 |
``` cpp
|
| 2085 |
ostreambuf_iterator(ostream_type& s) noexcept;
|
| 2086 |
```
|
| 2087 |
|
| 2088 |
+
*Requires:* `s.rdbuf()` shall not be a null pointer.
|
| 2089 |
|
| 2090 |
+
*Effects:* Initializes `sbuf_` with `s.rdbuf()`.
|
| 2091 |
|
| 2092 |
``` cpp
|
| 2093 |
ostreambuf_iterator(streambuf_type* s) noexcept;
|
| 2094 |
```
|
| 2095 |
|
| 2096 |
*Requires:* `s` shall not be a null pointer.
|
| 2097 |
|
| 2098 |
+
*Effects:* Initializes `sbuf_` with `s`.
|
| 2099 |
|
| 2100 |
#### `ostreambuf_iterator` operations <a id="ostreambuf.iter.ops">[[ostreambuf.iter.ops]]</a>
|
| 2101 |
|
| 2102 |
``` cpp
|
| 2103 |
ostreambuf_iterator<charT,traits>&
|
| 2104 |
operator=(charT c);
|
| 2105 |
```
|
| 2106 |
|
| 2107 |
+
*Effects:* If `failed()` yields `false`, calls `sbuf_->sputc(c)`;
|
| 2108 |
otherwise has no effect.
|
| 2109 |
|
| 2110 |
*Returns:* `*this`.
|
| 2111 |
|
| 2112 |
``` cpp
|
|
|
|
| 2125 |
``` cpp
|
| 2126 |
bool failed() const noexcept;
|
| 2127 |
```
|
| 2128 |
|
| 2129 |
*Returns:* `true` if in any prior use of member `operator=`, the call to
|
| 2130 |
+
`sbuf_->sputc()` returned `traits::eof()`; or `false` otherwise.
|
| 2131 |
|
| 2132 |
+
## range access <a id="iterator.range">[[iterator.range]]</a>
|
| 2133 |
|
| 2134 |
In addition to being available via inclusion of the `<iterator>` header,
|
| 2135 |
the function templates in [[iterator.range]] are available when any of
|
| 2136 |
the following headers are included: `<array>`, `<deque>`,
|
| 2137 |
`<forward_list>`, `<list>`, `<map>`, `<regex>`, `<set>`, `<string>`,
|
|
|
|
| 2150 |
```
|
| 2151 |
|
| 2152 |
*Returns:* `c.end()`.
|
| 2153 |
|
| 2154 |
``` cpp
|
| 2155 |
+
template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
|
| 2156 |
```
|
| 2157 |
|
| 2158 |
*Returns:* `array`.
|
| 2159 |
|
| 2160 |
``` cpp
|
| 2161 |
+
template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
|
| 2162 |
```
|
| 2163 |
|
| 2164 |
*Returns:* `array + N`.
|
| 2165 |
|
| 2166 |
+
``` cpp
|
| 2167 |
+
template <class C> constexpr auto cbegin(const C& c) noexcept(noexcept(std::begin(c)))
|
| 2168 |
+
-> decltype(std::begin(c));
|
| 2169 |
+
```
|
| 2170 |
+
|
| 2171 |
+
*Returns:* `std::begin(c)`.
|
| 2172 |
+
|
| 2173 |
+
``` cpp
|
| 2174 |
+
template <class C> constexpr auto cend(const C& c) noexcept(noexcept(std::end(c)))
|
| 2175 |
+
-> decltype(std::end(c));
|
| 2176 |
+
```
|
| 2177 |
+
|
| 2178 |
+
*Returns:* `std::end(c)`.
|
| 2179 |
+
|
| 2180 |
+
``` cpp
|
| 2181 |
+
template <class C> auto rbegin(C& c) -> decltype(c.rbegin());
|
| 2182 |
+
template <class C> auto rbegin(const C& c) -> decltype(c.rbegin());
|
| 2183 |
+
```
|
| 2184 |
+
|
| 2185 |
+
*Returns:* `c.rbegin()`.
|
| 2186 |
+
|
| 2187 |
+
``` cpp
|
| 2188 |
+
template <class C> auto rend(C& c) -> decltype(c.rend());
|
| 2189 |
+
template <class C> auto rend(const C& c) -> decltype(c.rend());
|
| 2190 |
+
```
|
| 2191 |
+
|
| 2192 |
+
*Returns:* `c.rend()`.
|
| 2193 |
+
|
| 2194 |
+
``` cpp
|
| 2195 |
+
template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]);
|
| 2196 |
+
```
|
| 2197 |
+
|
| 2198 |
+
*Returns:* `reverse_iterator<T*>(array + N)`.
|
| 2199 |
+
|
| 2200 |
+
``` cpp
|
| 2201 |
+
template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]);
|
| 2202 |
+
```
|
| 2203 |
+
|
| 2204 |
+
*Returns:* `reverse_iterator<T*>(array)`.
|
| 2205 |
+
|
| 2206 |
+
``` cpp
|
| 2207 |
+
template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il);
|
| 2208 |
+
```
|
| 2209 |
+
|
| 2210 |
+
*Returns:* `reverse_iterator<const E*>(il.end())`.
|
| 2211 |
+
|
| 2212 |
+
``` cpp
|
| 2213 |
+
template <class E> reverse_iterator<const E*> rend(initializer_list<E> il);
|
| 2214 |
+
```
|
| 2215 |
+
|
| 2216 |
+
*Returns:* `reverse_iterator<const E*>(il.begin())`.
|
| 2217 |
+
|
| 2218 |
+
``` cpp
|
| 2219 |
+
template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c));
|
| 2220 |
+
```
|
| 2221 |
+
|
| 2222 |
+
*Returns:* `std::rbegin(c)`.
|
| 2223 |
+
|
| 2224 |
+
``` cpp
|
| 2225 |
+
template <class C> auto crend(const C& c) -> decltype(std::rend(c));
|
| 2226 |
+
```
|
| 2227 |
+
|
| 2228 |
+
*Returns:* `std::rend(c)`.
|
| 2229 |
+
|
| 2230 |
<!-- Link reference definitions -->
|
| 2231 |
[back.insert.iter.cons]: #back.insert.iter.cons
|
| 2232 |
[back.insert.iter.op*]: #back.insert.iter.op*
|
| 2233 |
[back.insert.iter.op++]: #back.insert.iter.op++
|
| 2234 |
[back.insert.iter.op=]: #back.insert.iter.op=
|
|
|
|
| 2306 |
[output.iterators]: #output.iterators
|
| 2307 |
[predef.iterators]: #predef.iterators
|
| 2308 |
[random.access.iterators]: #random.access.iterators
|
| 2309 |
[reverse.iter.cons]: #reverse.iter.cons
|
| 2310 |
[reverse.iter.conv]: #reverse.iter.conv
|
| 2311 |
+
[reverse.iter.make]: #reverse.iter.make
|
| 2312 |
[reverse.iter.op!=]: #reverse.iter.op!=
|
| 2313 |
[reverse.iter.op+]: #reverse.iter.op+
|
| 2314 |
[reverse.iter.op++]: #reverse.iter.op++
|
| 2315 |
[reverse.iter.op+=]: #reverse.iter.op+=
|
| 2316 |
[reverse.iter.op-]: #reverse.iter.op-
|