Skip to content

Commit fae8c55

Browse files
Implement P3223R2 Making istream::ignore() Less Surprising (#5604)
1 parent 9ed9371 commit fae8c55

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

stl/inc/istream

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ public:
528528
return *this;
529529
}
530530

531+
template <class _CharType = _Elem, enable_if_t<is_same_v<_CharType, char>, int> = 0>
532+
basic_istream& ignore(const streamsize _Count, const _Elem _Delim) {
533+
return ignore(_Count, _Traits::to_int_type(_Delim));
534+
}
535+
531536
basic_istream& __CLR_OR_THIS_CALL read(_Elem* _Str, streamsize _Count) { // read up to _Count characters into buffer
532537
ios_base::iostate _State = ios_base::goodbit;
533538
_Chcount = 0;

stl/inc/yvals_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
// (__cpp_lib_freestanding_algorithm and __cpp_lib_freestanding_array only)
8181
// P2937R0 Freestanding Library: Remove strtok
8282
// P2968R2 Make std::ignore A First-Class Object
83+
// P3223R2 Making istream::ignore() Less Surprising
8384
// P3323R1 Forbid atomic<cv T>, Specify atomic_ref<cv T>
8485
// (for atomic<cv T>)
8586

tests/std/tests/VSO_0000000_nullptr_stream_out/test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,17 @@ int main() {
6464
STATIC_ASSERT(OstreamInsertable<PublicOstream, int>);
6565
STATIC_ASSERT(OstreamInsertable<PrivateOstream&, int>);
6666
STATIC_ASSERT(!OstreamInsertable<PrivateOstream, int>);
67+
68+
{ // Test P3223R2 "Making std::istream::ignore Less Surprising"
69+
istringstream in{"\xF0\x9F\xA4\xA1 Clown Face"};
70+
decltype(auto) ret = in.ignore(100, '\xA1');
71+
72+
STATIC_ASSERT(is_same_v<decltype(ret), istream&>);
73+
assert(&ret == &static_cast<istream&>(in));
74+
assert(in.gcount() == 4);
75+
76+
string s;
77+
in >> s;
78+
assert(s == "Clown");
79+
}
6780
}

0 commit comments

Comments
 (0)