-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathiterator.html
136 lines (108 loc) · 4.92 KB
/
iterator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<cxx-clause id="iterator">
<h1>Iterators library</h1>
<cxx-section id="iterator.syn">
<h1>Header <code><experimental/iterator></code> synopsis</h1>
<pre><code>#include <iterator>
namespace std::experimental::inline fundamentals_v3 {
<cxx-ref insynopsis="" to="iterator.ostream.joiner"></cxx-ref>
template <class DelimT, class charT = char, class traits = char_traits<charT>>
class ostream_joiner;
template <class charT, class traits, class DelimT>
ostream_joiner<decay_t<DelimT>, charT, traits>
make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);
} // namespace std::experimental::inline fundamentals_v3</code></pre>
</cxx-section>
<cxx-section id="iterator.ostream.joiner">
<h1>Class template <code>ostream_joiner</code></h1>
<cxx-section id="iterator.ostream.joiner.overview">
<h1>Overview</h1>
<p>
<code>ostream_joiner</code> writes (using <code>operator<<</code>) successive elements onto the output stream from which it was constructed.
The delimiter that it was constructed with is written to the stream between every two <code>T</code>s that are written.
It is not possible to get a value out of the output iterator.
Its only use is as an output iterator in situations like
</p>
<pre><code>while (first != last)
*result++ = *first++;</code></pre>
<p>
<code>ostream_joiner</code> is defined as
</p>
<pre><code>namespace std::experimental::inline fundamentals_v3 {
template <class DelimT, class charT = char, class traits = char_traits<charT>>
class ostream_joiner {
public:
using char_type = charT;
using traits_type = traits;
using ostream_type = basic_ostream<charT, traits>;
using iterator_category = output_iterator_tag;
using value_type = void;
using difference_type = void;
using pointer = void;
using reference = void;
ostream_joiner(ostream_type& s, const DelimT& delimiter);
ostream_joiner(ostream_type& s, DelimT&& delimiter);
template<typename T>
ostream_joiner& operator=(const T& value);
ostream_joiner& operator*() noexcept;
ostream_joiner& operator++() noexcept;
ostream_joiner& operator++(int) noexcept;
private:
ostream_type* out_stream; <i>// exposition only</i>
DelimT delim; <i>// exposition only</i>
bool first_element; <i>// exposition only</i>
};
} // namespace std::experimental::inline fundamentals_v3</code></pre>
</cxx-section>
<cxx-section id="iterator.ostream.joiner.cons">
<h1>Constructor</h1>
<cxx-function>
<cxx-signature>ostream_joiner(ostream_type& s, const DelimT& delimiter);</cxx-signature>
<cxx-effects>
Initializes <code>out_stream</code> with <code>std::addressof(s)</code>,
<code>delim</code> with <code>delimiter</code>,
and <code>first_element</code> with <code>true</code>.
</cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>ostream_joiner(ostream_type& s, DelimT&& delimiter);</cxx-signature>
<cxx-effects>
Initializes <code>out_stream</code> with <code>std::addressof(s)</code>,
<code>delim</code> with <code>move(delimiter)</code>,
and <code>first_element</code> with <code>true</code>.
</cxx-effects>
</cxx-function>
</cxx-section>
<cxx-section id="iterator.ostream.joiner.ops">
<h1>Operations</h1>
<cxx-function>
<cxx-signature>template<typename T>
ostream_joiner& operator=(const T& value);</cxx-signature>
<cxx-effects>
<pre style="clear:left"><code>if (!first_element)
*out_stream << delim;
first_element = false;
*out_stream << value;
return *this;</code></pre>
</cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>ostream_joiner& operator*() noexcept;</cxx-signature>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>ostream_joiner& operator++() noexcept;</cxx-signature>
<cxx-signature>ostream_joiner& operator++(int) noexcept;</cxx-signature>
<cxx-returns><code>*this</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="iterator.ostream.joiner.creation">
<h1>Creation function</h1>
<cxx-function>
<cxx-signature>template <class charT, class traits, class DelimT>
ostream_joiner<decay_t<DelimT>, charT, traits>
make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);</cxx-signature>
<cxx-returns><code>ostream_joiner<decay_t<DelimT>, charT, traits>(os, forward<DelimT>(delimiter));</code></cxx-returns>
</cxx-function>
</cxx-section>
</cxx-section>
</cxx-clause>