On Wed, Nov 12, 2025 at 12:26 AM Jonathan Wakely <[email protected]> wrote: > > On Sun, 02 Nov 2025 at 15:45 +0800, Yuao Ma wrote: > >Hi all, > > > >This patch implements paper P3223R2, which adds a new overload to > >std::istream::ignore for char_type. > >Since this function dates back to C++98, I've used type_traits from > >the ext rather than the std header to maintain compatibility. > > > >Please take a look when you have time. > > I (along with other libstdc++ devs) was at the WG21 meeting for the > past week and am still recovering from jetlag. > > >Thanks, > >Yuao > > >From 80f609ffb64c4aba74df13c97f99ad72c2abf1bb Mon Sep 17 00:00:00 2001 > >From: Yuao Ma <[email protected]> > >Date: Sun, 2 Nov 2025 15:39:38 +0800 > >Subject: [PATCH] libstdc++: Implement P3223R2 Making std::istream::ignore > >less > > surprising > > > >libstdc++-v3/ChangeLog: > > > > * include/std/istream: Add a overload for char_type. > > * testsuite/27_io/basic_istream/ignore/char/4.cc: New test. > >--- > > libstdc++-v3/include/std/istream | 8 +++++- > > .../27_io/basic_istream/ignore/char/4.cc | 25 +++++++++++++++++++ > > 2 files changed, 32 insertions(+), 1 deletion(-) > > create mode 100644 > > libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/4.cc > > > >diff --git a/libstdc++-v3/include/std/istream > >b/libstdc++-v3/include/std/istream > >index d5bb1876001..8a392782d68 100644 > >--- a/libstdc++-v3/include/std/istream > >+++ b/libstdc++-v3/include/std/istream > >@@ -38,6 +38,7 @@ > > #endif > > > > #include <bits/requires_hosted.h> // iostreams > >+#include <ext/type_traits.h> // __enable_if > > > > #include <ios> > > #include <ostream> > >@@ -537,11 +538,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > * is extracted); note that this condition will never occur if > > * @a __delim equals @c traits::eof(). > > * > >- * NB: Provide three overloads, instead of the single function > >+ * NB: Provide four overloads, instead of the single function > > * (with defaults) mandated by the Standard: this leads to a > > * better performing implementation, while still conforming to > > * the Standard. > > */ > >+ template<typename _Tp> > >+ typename __gnu_cxx::__enable_if<__are_same<_Tp, char>::__value, > >__istream_type&>::__type > > This seems to add std::wistream::ignore(streamsize, char) which is not > what the paper says. > > The new ignore should only be present for basic_istream<char, traits> > and not other specializations. The Constraints: element means the > function is only present for the char specializations, it doesn't > mean that the overload is only enabled when the second argument is > char. > > I was intending something like: > > #if __cplusplus > 202302L > basic_istream& > ignore(streamsize __n, char __delim) requires same_as<_CharT, char> > #else > template<typename _Tp = _CharT> > typename > __gnu_cxx::__enable_if<__are_same<_Tp, char>::__value, > basic_istream&>::__type > #endif >
Default template parameters were introduced in C++11, so we may need a separate preprocessor branch for C++98/03. And I'm a bit confused here. Why does adding `_Tp = _CharT` prevent the overload from appearing for wstream? I'm not sure what I'm missing. Yuao
