Skip to content

Commit ca333c7

Browse files
committed
P3223R2 Making std::istream::ignore less surprising
1 parent a8d9618 commit ca333c7

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

source/compatibility.tex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,28 @@
285285
\end{codeblock}
286286
\end{example}
287287

288+
\rSec2[diff.cpp23.io]{\ref{input.output}: input/output library}
289+
290+
\diffref{istream.unformatted}
291+
\change
292+
Overloaded \tcode{std::basic_istream<char, traits>::ignore}.
293+
\rationale
294+
Allow \tcode{char} values to be used as delimiters.
295+
\effect
296+
Calls to \tcode{istream::ignore} with a second argument of \tcode{char} type
297+
can change behavior.
298+
Calls to \tcode{istream::ignore} with a second argument that is neither
299+
\tcode{int} nor \tcode{char} type can become ill-formed.
300+
\begin{example}
301+
\begin{codeblock}
302+
std::istringstream in("\xF0\x9F\xA4\xA1 Clown Face");
303+
in.ignore(100, '\xA1'); // ignore up to \tcode{'\textbackslash{}xA1'} delimiter,
304+
// previously might have ignored to EOF
305+
in.ignore(100, -1L); // ambiguous overload,
306+
// previously equivalent to \tcode{(int)-1L}
307+
\end{codeblock}
308+
\end{example}
309+
288310
\rSec2[diff.cpp23.depr]{\ref{depr}: compatibility features}
289311

290312
\nodiffref

source/iostreams.tex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4363,6 +4363,7 @@
43634363
basic_istream& getline(char_type* s, streamsize n, char_type delim);
43644364

43654365
basic_istream& ignore(streamsize n = 1, int_type delim = traits::eof());
4366+
basic_istream& ignore(streamsize n, char_type delim);
43664367
int_type peek();
43674368
basic_istream& read (char_type* s, streamsize n);
43684369
streamsize readsome(char_type* s, streamsize n);
@@ -5426,6 +5427,21 @@
54265427
\tcode{*this}.
54275428
\end{itemdescr}
54285429

5430+
\indexlibrarymember{ignore}{basic_istream}%
5431+
\begin{itemdecl}
5432+
basic_istream& ignore(streamsize n, char_type delim);
5433+
\end{itemdecl}
5434+
5435+
\begin{itemdescr}
5436+
\pnum
5437+
\constraints
5438+
\tcode{is_same_v<char_type, char>} is \tcode{true}.
5439+
5440+
\pnum
5441+
\effects
5442+
Equivalent to: \tcode{return ignore(n, traits::to_int_type(delim));}
5443+
\end{itemdescr}
5444+
54295445
\indexlibrarymember{peek}{basic_istream}%
54305446
\begin{itemdecl}
54315447
int_type peek();

0 commit comments

Comments
 (0)