Skip to content

Commit a9c1f08

Browse files
jwakelytkoeppe
authored andcommitted
P3223R2 Making std::istream::ignore less surprising
1 parent c25d1e8 commit a9c1f08

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
@@ -330,6 +330,28 @@
330330
\end{codeblock}
331331
\end{example}
332332

333+
\rSec2[diff.cpp23.io]{\ref{input.output}: input/output library}
334+
335+
\diffref{istream.unformatted}
336+
\change
337+
Overloaded \tcode{std::basic_istream<char, traits>::ignore}.
338+
\rationale
339+
Allow \tcode{char} values to be used as delimiters.
340+
\effect
341+
Calls to \tcode{istream::ignore} with a second argument of \tcode{char} type
342+
can change behavior.
343+
Calls to \tcode{istream::ignore} with a second argument that is neither
344+
\tcode{int} nor \tcode{char} type can become ill-formed.
345+
\begin{example}
346+
\begin{codeblock}
347+
std::istringstream in("\xF0\x9F\xA4\xA1 Clown Face");
348+
in.ignore(100, '\xA1'); // ignore up to \tcode{'\textbackslash{}xA1'} delimiter,
349+
// previously might have ignored to EOF
350+
in.ignore(100, -1L); // ambiguous overload,
351+
// previously equivalent to \tcode{(int)-1L}
352+
\end{codeblock}
353+
\end{example}
354+
333355
\rSec2[diff.cpp23.depr]{\ref{depr}: compatibility features}
334356

335357
\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)