From Jason Turner

[spanbuf]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpepqlodzj/{from.md → to.md} +230 -0
tmp/tmpepqlodzj/{from.md → to.md} RENAMED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class template `basic_spanbuf` <a id="spanbuf">[[spanbuf]]</a>
2
+
3
+ #### General <a id="spanbuf.general">[[spanbuf.general]]</a>
4
+
5
+ ``` cpp
6
+ namespace std {
7
+ template<class charT, class traits = char_traits<charT>>
8
+ class basic_spanbuf
9
+ : public basic_streambuf<charT, traits> {
10
+ public:
11
+ using char_type = charT;
12
+ using int_type = typename traits::int_type;
13
+ using pos_type = typename traits::pos_type;
14
+ using off_type = typename traits::off_type;
15
+ using traits_type = traits;
16
+
17
+ // [spanbuf.cons], constructors
18
+ basic_spanbuf() : basic_spanbuf(ios_base::in | ios_base::out) {}
19
+ explicit basic_spanbuf(ios_base::openmode which)
20
+ : basic_spanbuf(std::span<charT>(), which) {}
21
+ explicit basic_spanbuf(std::span<charT> s,
22
+ ios_base::openmode which = ios_base::in | ios_base::out);
23
+ basic_spanbuf(const basic_spanbuf&) = delete;
24
+ basic_spanbuf(basic_spanbuf&& rhs);
25
+
26
+ // [spanbuf.assign], assignment and swap
27
+ basic_spanbuf& operator=(const basic_spanbuf&) = delete;
28
+ basic_spanbuf& operator=(basic_spanbuf&& rhs);
29
+ void swap(basic_spanbuf& rhs);
30
+
31
+ // [spanbuf.members], member functions
32
+ std::span<charT> span() const noexcept;
33
+ void span(std::span<charT> s) noexcept;
34
+
35
+ protected:
36
+ // [spanbuf.virtuals], overridden virtual functions
37
+ basic_streambuf<charT, traits>* setbuf(charT*, streamsize) override;
38
+ pos_type seekoff(off_type off, ios_base::seekdir way,
39
+ ios_base::openmode which = ios_base::in | ios_base::out) override;
40
+ pos_type seekpos(pos_type sp,
41
+ ios_base::openmode which = ios_base::in | ios_base::out) override;
42
+
43
+ private:
44
+ ios_base::openmode mode; // exposition only
45
+ std::span<charT> buf; // exposition only
46
+ };
47
+ }
48
+ ```
49
+
50
+ The class template `basic_spanbuf` is derived from `basic_streambuf` to
51
+ associate possibly the input sequence and possibly the output sequence
52
+ with a sequence of arbitrary characters. The sequence is provided by an
53
+ object of class `span<charT>`.
54
+
55
+ For the sake of exposition, the maintained data is presented here as:
56
+
57
+ - `ios_base::openmode mode`, has `in` set if the input sequence can be
58
+ read, and `out` set if the output sequence can be written.
59
+ - `std::span<charT> buf` is the view to the underlying character
60
+ sequence.
61
+
62
+ #### Constructors <a id="spanbuf.cons">[[spanbuf.cons]]</a>
63
+
64
+ ``` cpp
65
+ explicit basic_spanbuf(std::span<charT> s,
66
+ ios_base::openmode which = ios_base::in | ios_base::out);
67
+ ```
68
+
69
+ *Effects:* Initializes the base class with `basic_streambuf()`
70
+ [[streambuf.cons]], and *mode* with `which`. Initializes the internal
71
+ pointers as if calling `span(s)`.
72
+
73
+ ``` cpp
74
+ basic_spanbuf(basic_spanbuf&& rhs);
75
+ ```
76
+
77
+ *Effects:* Initializes the base class with `std::move(rhs)` and *mode*
78
+ with `std::move(rhs.`*`mode`*`)` and *buf* with
79
+ `std::move(rhs.`*`buf`*`)`. The sequence pointers in `*this` (`eback()`,
80
+ `gptr()`, `egptr()`, `pbase()`, `pptr()`, `epptr()`) obtain the values
81
+ which `rhs` had. It is *implementation-defined* whether
82
+ `rhs.`*`buf`*`.empty()` returns `true` after the move.
83
+
84
+ *Ensures:* Let `rhs_p` refer to the state of `rhs` just prior to this
85
+ construction.
86
+
87
+ - `span().data() == rhs_p.span().data()`
88
+ - `span().size() == rhs_p.span().size()`
89
+ - `eback() == rhs_p.eback()`
90
+ - `gptr() == rhs_p.gptr()`
91
+ - `egptr() == rhs_p.egptr()`
92
+ - `pbase() == rhs_p.pbase()`
93
+ - `pptr() == rhs_p.pptr()`
94
+ - `epptr() == rhs_p.epptr()`
95
+ - `getloc() == rhs_p.getloc()`
96
+
97
+ #### Assignment and swap <a id="spanbuf.assign">[[spanbuf.assign]]</a>
98
+
99
+ ``` cpp
100
+ basic_spanbuf& operator=(basic_spanbuf&& rhs);
101
+ ```
102
+
103
+ *Effects:* Equivalent to:
104
+
105
+ ``` cpp
106
+ basic_spanbuf tmp{std::move(rhs)};
107
+ this->swap(tmp);
108
+ return *this;
109
+ ```
110
+
111
+ ``` cpp
112
+ void swap(basic_spanbuf& rhs);
113
+ ```
114
+
115
+ *Effects:* Equivalent to:
116
+
117
+ ``` cpp
118
+ basic_streambuf<charT, traits>::swap(rhs);
119
+ std::swap(mode, rhs.mode);
120
+ std::swap(buf, rhs.buf);
121
+ ```
122
+
123
+ ``` cpp
124
+ template<class charT, class traits>
125
+ void swap(basic_spanbuf<charT, traits>& x, basic_spanbuf<charT, traits>& y);
126
+ ```
127
+
128
+ *Effects:* Equivalent to `x.swap(y)`.
129
+
130
+ #### Member functions <a id="spanbuf.members">[[spanbuf.members]]</a>
131
+
132
+ ``` cpp
133
+ std::span<charT> span() const noexcept;
134
+ ```
135
+
136
+ *Returns:* If `ios_base::out` is set in *mode*, returns
137
+ `std::span<charT>(pbase(), pptr())`, otherwise returns *buf*.
138
+
139
+ [*Note 1*: In contrast to `basic_stringbuf`, the underlying sequence
140
+ never grows and is not owned. An owning copy can be obtained by
141
+ converting the result to `basic_string<charT>`. — *end note*]
142
+
143
+ ``` cpp
144
+ void span(std::span<charT> s) noexcept;
145
+ ```
146
+
147
+ *Effects:* *`buf`*` = s`. Initializes the input and output sequences
148
+ according to *mode*.
149
+
150
+ *Ensures:*
151
+
152
+ - If `ios_base::out` is set in *mode*,
153
+ `pbase() == s.data() && epptr() == pbase() + s.size()` is `true`;
154
+ - in addition, if `ios_base::ate` is set in *mode*,
155
+ `pptr() == pbase() + s.size()` is `true`,
156
+ - otherwise `pptr() == pbase()` is `true`.
157
+ - If `ios_base::in` is set in *mode*,
158
+ `eback() == s.data() && gptr() == eback() && egptr() == eback() + s.size()`
159
+ is `true`.
160
+
161
+ #### Overridden virtual functions <a id="spanbuf.virtuals">[[spanbuf.virtuals]]</a>
162
+
163
+ [*Note 1*: Because the underlying buffer is of fixed size, neither
164
+ `overflow`, `underflow`, nor `pbackfail` can provide useful
165
+ behavior. — *end note*]
166
+
167
+ ``` cpp
168
+ pos_type seekoff(off_type off, ios_base::seekdir way,
169
+ ios_base::openmode which = ios_base::in | ios_base::out) override;
170
+ ```
171
+
172
+ *Effects:* Alters the stream position within one or both of the
173
+ controlled sequences, if possible, as follows:
174
+
175
+ - If `ios_base::in` is set in `which`, positions the input sequence;
176
+ `xnext` is `gptr()`, `xbeg` is `eback()`.
177
+ - If `ios_base::out` is set in `which`, positions the output sequence;
178
+ `xnext` is `pptr()`, `xbeg` is `pbase()`.
179
+
180
+ If both `ios_base::in` and `ios_base::out` are set in `which` and `way`
181
+ is `ios_base::cur`, the positioning operation fails.
182
+
183
+ For a sequence to be positioned, if its next pointer `xnext` (either
184
+ `gptr()` or `pptr()`) is a null pointer and the new offset `newoff` as
185
+ computed below is nonzero, the positioning operation fails. Otherwise,
186
+ the function determines `baseoff` as a value of type `off_type` as
187
+ follows:
188
+
189
+ - `0` when `way` is `ios_base::beg`;
190
+ - `(pptr() - pbase())` for the output sequence, or `(gptr() - eback())`
191
+ for the input sequence when `way` is `ios_base::cur`;
192
+ - when `way` is `ios_base::end` :
193
+ - `(pptr() - pbase())` if `ios_base::out` is set in *mode* and
194
+ `ios_base::in` is not set in *mode*,
195
+ - `buf.size()` otherwise.
196
+
197
+ If `baseoff` + `off` would overflow, or if `baseoff` + `off` is less
198
+ than zero, or if `baseoff` + `off` is greater than *`buf`*`.size()`, the
199
+ positioning operation fails. Otherwise, the function computes
200
+
201
+ ``` cpp
202
+ off_type newoff = baseoff + off;
203
+ ```
204
+
205
+ and assigns `xbeg + newoff` to the next pointer `xnext`.
206
+
207
+ *Returns:* `pos_type(off_type(-1))` if the positioning operation fails;
208
+ `pos_type(newoff)` otherwise.
209
+
210
+ ``` cpp
211
+ pos_type seekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out) override;
212
+ ```
213
+
214
+ *Effects:* Equivalent to:
215
+
216
+ ``` cpp
217
+ return seekoff(off_type(sp), ios_base::beg, which);
218
+ ```
219
+
220
+ ``` cpp
221
+ basic_streambuf<charT, traits>* setbuf(charT* s, streamsize n) override;
222
+ ```
223
+
224
+ *Effects:* Equivalent to:
225
+
226
+ ``` cpp
227
+ this->span(std::span<charT>(s, n));
228
+ return this;
229
+ ```
230
+