Skip to content

Commit aa7ce10

Browse files
committed
[libc++][istream] P3223R2 Making std::istream::ignore less surprising
Implements [P3223R2](https://wg21.link/P3223R2) - cplusplus/draft#7996
1 parent 9f733f4 commit aa7ce10

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

libcxx/docs/ReleaseNotes/21.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Implemented Papers
5353
- P2711R1: Making multi-param constructors of ``views`` ``explicit`` (`Github <https://github.com/llvm/llvm-project/issues/105252>`__)
5454
- P2770R0: Stashing stashing ``iterators`` for proper flattening (`Github <https://github.com/llvm/llvm-project/issues/105250>`__)
5555
- P2655R3: ``common_reference_t`` of ``reference_wrapper`` Should Be a Reference Type (`Github <https://github.com/llvm/llvm-project/issues/105260>`__)
56+
- P3223R2: Making ``std::istream::ignore`` less surprising
5657

5758
Improvements and New Features
5859
-----------------------------

libcxx/include/istream

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public:
7070
basic_istream& getline(char_type* s, streamsize n, char_type delim);
7171
7272
basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
73+
basic_istream& ignore(streamsize n, char_type delim); // Since C++26
7374
int_type peek();
7475
basic_istream& read (char_type* s, streamsize n);
7576
streamsize readsome(char_type* s, streamsize n);
@@ -292,6 +293,13 @@ public:
292293
basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
293294

294295
basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
296+
# if __LIBCPP_STD_VER >= 26
297+
basic_istream& ignore(streamsize __n, char_type __delim)
298+
requires is_same_v<char_type, char>
299+
{
300+
return ignore(__n, traits::to_int_type(__delim));
301+
}
302+
# endif
295303
int_type peek();
296304
basic_istream& read(char_type* __s, streamsize __n);
297305
streamsize readsome(char_type* __s, streamsize __n);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++26
10+
11+
// Requires 396145d in the built library.
12+
// XFAIL: using-built-library-before-llvm-9
13+
14+
// <istream>
15+
16+
// basic_istream& ignore(streamsize n, char_type delim);
17+
18+
#include <cassert>
19+
#include <istream>
20+
#include <sstream>
21+
#include <string>
22+
23+
#include "test_macros.h"
24+
25+
int main(int, char**) {
26+
std::istringstream in("\xF0\x9F\xA4\xA1 Clown Face");
27+
in.ignore(100, '\xA1'); // ignore up to '\xA1' delimiter,
28+
// previously might have ignored to EOF
29+
30+
assert(in.gcount() == 4); // 4 bytes were ignored
31+
assert(in.peek() == ' '); // next character is a space
32+
33+
std::string s1; // read the next word
34+
in >> s1;
35+
assert(s1 == "Clown");
36+
37+
in.ignore(100, -1L); // ambiguous overload,
38+
// previously equivalent to (int)-1L
39+
40+
return 0;
41+
}

0 commit comments

Comments
 (0)