[PATCH] libstdc++: Implement stringstream from string_view [P2495R3]
Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view where the existing functions take a string. libstdc++-v3/ChangeLog: P2495R3 stringstream to init from string_view-ish * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/std/bits/version.def, .h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/3.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/2.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/4.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/2.cc: New tests. --- libstdc++-v3/ChangeLog| 11 + libstdc++-v3/include/bits/version.def | 11 +- libstdc++-v3/include/bits/version.h | 10 + libstdc++-v3/include/std/sstream | 181 +-- .../27_io/basic_istringstream/cons/char/2.cc | 193 .../27_io/basic_ostringstream/cons/char/4.cc | 193 .../27_io/basic_stringbuf/cons/char/3.cc | 216 ++ .../27_io/basic_stringstream/cons/char/2.cc | 194 8 files changed, 990 insertions(+), 19 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/2.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b45f8c2c7a5..ac0ff4a386f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -41,6 +41,17 @@ PR libstdc++/119246 * include/std/format: Updated check for _GLIBCXX_FORMAT_F128. +2025-05-14 Nathan Myers + P2495R3 stringstream to init from string_view-ish + * include/std/sstream: full implementation, really just + decls, requires clause and plumbing. + * include/std/bits/version.def, .h: new preprocessor symbol + __cpp_lib_sstream_from_string_view. + * testsuite/27_io/basic_stringbuf/cons/char/3.cc: New tests. + * testsuite/27_io/basic_istringstream/cons/char/2.cc: New tests. + * testsuite/27_io/basic_ostringstream/cons/char/4.cc: New tests. + * testsuite/27_io/basic_stringstream/cons/char/2.cc: New tests. + 2025-05-14 Tomasz Kamiński PR libstdc++/119125 diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 6ca148f0488..567c56b4117 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -649,7 +649,7 @@ ftms = { }; values = { v = 1; -/* For when there's no gthread. */ +// For when there is no gthread. cxxmin = 17; hosted = yes; gthread = no; @@ -1961,6 +1961,15 @@ ftms = { }; }; +ftms = { + name = sstream_from_string_view; + values = { +v = 202302; +cxxmin = 26; +hosted = yes; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 48a090c14a3..5d1beb83a25 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2193,4 +2193,14 @@ #endif /* !defined(__cpp_lib_modules) && defined(__glibcxx_want_modules) */ #undef __glibcxx_want_modules +#if !defined(__cpp_lib_sstream_from_string_view) +# if (__cplusplus > 202302L) && _GLIBCXX_HOSTED +# define __glibcxx_sstream_from_string_view 202302L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_sstream_from_string_view) +# define __cpp_lib_sstream_from_string_view 202302L +# endif +# endif +#endif /* !defined(__cpp_lib_sstream_from_string_view) && defined(__glibcxx_want_sstream_from_string_view) */ +#undef __glibcxx_want_sstream_from_string_view + #undef __glibcxx_want_all diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index ad0c16a91e8..9b2b0eb53fc 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -38,9 +38,14 @@ #endif #include // iostream +#include #include #include +#ifdef __cpp_lib_sstream_from_string_view +# include // is_convertible_v +#endif + #include // allocator_traits, __allocator_like #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI @@ -52,8 +57,6 @@ # define _GLIBCXX_SSTREAM_ALWAYS_INLINE [[__gnu__::__always_inline__]] #endif - - namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -159,6 +162,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { __rhs._M_sync(cons
[PATCH] libstdc++: Implement stringstream from string_view [P2495R3]
Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view where the existing functions take a string. libstdc++-v3/ChangeLog: P2495R3 stringstream to init from string_view-ish * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/std/bits/version.def, .h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/3.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/2.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/4.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/2.cc: New tests. --- libstdc++-v3/ChangeLog| 11 + libstdc++-v3/include/bits/version.def | 11 +- libstdc++-v3/include/bits/version.h | 10 + libstdc++-v3/include/std/sstream | 181 +-- .../27_io/basic_istringstream/cons/char/2.cc | 193 .../27_io/basic_ostringstream/cons/char/4.cc | 193 .../27_io/basic_stringbuf/cons/char/3.cc | 216 ++ .../27_io/basic_stringstream/cons/char/2.cc | 194 8 files changed, 990 insertions(+), 19 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/2.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b45f8c2c7a5..ac0ff4a386f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -41,6 +41,17 @@ PR libstdc++/119246 * include/std/format: Updated check for _GLIBCXX_FORMAT_F128. +2025-05-14 Nathan Myers + P2495R3 stringstream to init from string_view-ish + * include/std/sstream: full implementation, really just + decls, requires clause and plumbing. + * include/std/bits/version.def, .h: new preprocessor symbol + __cpp_lib_sstream_from_string_view. + * testsuite/27_io/basic_stringbuf/cons/char/3.cc: New tests. + * testsuite/27_io/basic_istringstream/cons/char/2.cc: New tests. + * testsuite/27_io/basic_ostringstream/cons/char/4.cc: New tests. + * testsuite/27_io/basic_stringstream/cons/char/2.cc: New tests. + 2025-05-14 Tomasz Kamiński PR libstdc++/119125 diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 6ca148f0488..567c56b4117 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -649,7 +649,7 @@ ftms = { }; values = { v = 1; -/* For when there's no gthread. */ +// For when there is no gthread. cxxmin = 17; hosted = yes; gthread = no; @@ -1961,6 +1961,15 @@ ftms = { }; }; +ftms = { + name = sstream_from_string_view; + values = { +v = 202302; +cxxmin = 26; +hosted = yes; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 48a090c14a3..5d1beb83a25 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2193,4 +2193,14 @@ #endif /* !defined(__cpp_lib_modules) && defined(__glibcxx_want_modules) */ #undef __glibcxx_want_modules +#if !defined(__cpp_lib_sstream_from_string_view) +# if (__cplusplus > 202302L) && _GLIBCXX_HOSTED +# define __glibcxx_sstream_from_string_view 202302L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_sstream_from_string_view) +# define __cpp_lib_sstream_from_string_view 202302L +# endif +# endif +#endif /* !defined(__cpp_lib_sstream_from_string_view) && defined(__glibcxx_want_sstream_from_string_view) */ +#undef __glibcxx_want_sstream_from_string_view + #undef __glibcxx_want_all diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index ad0c16a91e8..9b2b0eb53fc 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -38,9 +38,14 @@ #endif #include // iostream +#include #include #include +#ifdef __cpp_lib_sstream_from_string_view +# include // is_convertible_v +#endif + #include // allocator_traits, __allocator_like #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI @@ -52,8 +57,6 @@ # define _GLIBCXX_SSTREAM_ALWAYS_INLINE [[__gnu__::__always_inline__]] #endif - - namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -159,6 +162,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { __rhs._M_sync(cons
[PATCH v3] libstdc++: Implement stringstream from string_view [PR119741]
Change in V3: * Comment that p2495 specifies a drive-by constraint omitted as redundant * Adjust whitespace to fit in 80 columns Change in V2: * apply all review comments * remove redundant drive-by "requires" on ctor from string allocator arg * check allocators are plumbed through -- >8 -- Implement PR libstdc++/119741 (P2495R3) Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view in places where the existing functions take a string. libstdc++-v3/ChangeLog: PR libstdc++/119741 * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/bits/version.def, include/bits/version.h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/3.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/2.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/4.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/2.cc: New tests. --- libstdc++-v3/include/bits/version.def | 11 +- libstdc++-v3/include/bits/version.h | 10 + libstdc++-v3/include/std/sstream | 200 -- .../27_io/basic_istringstream/cons/char/2.cc | 187 .../27_io/basic_ostringstream/cons/char/4.cc | 186 .../27_io/basic_stringbuf/cons/char/3.cc | 196 + .../27_io/basic_stringstream/cons/char/2.cc | 196 + 7 files changed, 967 insertions(+), 19 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/2.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 282667eabda..8172bcd4e26 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -649,7 +649,7 @@ ftms = { }; values = { v = 1; -/* For when there's no gthread. */ +// For when there is no gthread. cxxmin = 17; hosted = yes; gthread = no; @@ -1945,6 +1945,15 @@ ftms = { }; }; +ftms = { + name = sstream_from_string_view; + values = { +v = 202302; +cxxmin = 26; +hosted = yes; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index bb7c0479c72..b4b487fba92 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2174,4 +2174,14 @@ #endif /* !defined(__cpp_lib_modules) && defined(__glibcxx_want_modules) */ #undef __glibcxx_want_modules +#if !defined(__cpp_lib_sstream_from_string_view) +# if (__cplusplus > 202302L) && _GLIBCXX_HOSTED +# define __glibcxx_sstream_from_string_view 202302L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_sstream_from_string_view) +# define __cpp_lib_sstream_from_string_view 202302L +# endif +# endif +#endif /* !defined(__cpp_lib_sstream_from_string_view) && defined(__glibcxx_want_sstream_from_string_view) */ +#undef __glibcxx_want_sstream_from_string_view + #undef __glibcxx_want_all diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index ad0c16a91e8..528756ed631 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -38,9 +38,14 @@ #endif #include // iostream +#include #include #include +#ifdef __cpp_lib_sstream_from_string_view +# include // is_convertible_v +#endif + #include // allocator_traits, __allocator_like #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI @@ -52,8 +57,6 @@ # define _GLIBCXX_SSTREAM_ALWAYS_INLINE [[__gnu__::__always_inline__]] #endif - - namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -159,6 +162,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { __rhs._M_sync(const_cast(__rhs._M_string.data()), 0, 0); } #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI + // P0408 Efficient access to basic_stringbuf buffer explicit basic_stringbuf(const allocator_type& __a) : basic_stringbuf(ios_base::in | std::ios_base::out, __a) @@ -197,7 +201,36 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 | ios_base::out) : basic_stringbuf(__s, __mode, allocator_type{}) { } +#endif + +#ifdef __cpp_lib_sstream_from_string_view + template + explicit + basic_stringbuf(const _Tp& __t, + ios_base::openmode __mode = ios_base::in | ios_base::out) + requires (is_convertible_v>) + : basic_stringbu
[PATCH v4] libstdc++: stringstream ctors from string_view [PR119741]
Change in V4: * Rename tests to string_view.cc * Adapt tests to cons/wchar_t directories * Define symbol __cpp_lib_sstream_from_string_view as 202406 * Define symbol __glibcxx_want_sstream_from_string_view before version.h * Include version.h after other includes * No include type_traits * Drive-by comment moved to commit message * Each `explicit` on its own line * Run tests even when using old COW string Change in V3: * Comment that p2495 specifies a drive-by constraint omitted as redundant * Adjust whitespace to fit in 80 columns Change in V2: * Apply all review comments * Remove redundant drive-by "requires" on ctor from string allocator arg * Check allocators are plumbed through -- >8 -- Implement PR libstdc++/119741 (P2495R3). Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view in places where the existing ctors and function take a string. Note this change omits the constraint applied to the istringstream constructor from string cited as a "drive-by" in P2495R3, as we have determined it is redundant. libstdc++-v3/ChangeLog: PR libstdc++/119741 * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/bits/version.def, include/bits/version.h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringbuf/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/wchar_t/string_view.cc: New tests. --- libstdc++-v3/include/bits/version.def | 11 +- libstdc++-v3/include/bits/version.h | 10 + libstdc++-v3/include/std/sstream | 198 +++-- .../cons/char/string_view.cc | 195 + .../cons/wchar_t/string_view.cc | 3 + .../cons/char/string_view.cc | 194 + .../cons/wchar_t/string_view.cc | 3 + .../basic_stringbuf/cons/char/string_view.cc | 205 ++ .../cons/wchar_t/string_view.cc | 3 + .../cons/char/string_view.cc | 204 + .../cons/wchar_t/string_view.cc | 3 + 11 files changed, 1010 insertions(+), 19 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/string_view.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/string_view.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/string_view.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/string_view.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/string_view.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/string_view.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/string_view.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/string_view.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 282667eabda..53bf72d95c2 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -649,7 +649,7 @@ ftms = { }; values = { v = 1; -/* For when there's no gthread. */ +// For when there is no gthread. cxxmin = 17; hosted = yes; gthread = no; @@ -1945,6 +1945,15 @@ ftms = { }; }; +ftms = { + name = sstream_from_string_view; + values = { +v = 202306; +cxxmin = 26; +hosted = yes; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index bb7c0479c72..0b932183e5b 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2174,4 +2174,14 @@ #endif /* !defined(__cpp_lib_modules) && defined(__glibcxx_want_modules) */ #undef __glibcxx_want_modules +#if !defined(__cpp_lib_sstream_from_string_view) +# if (__cplusplus >= 202306L) && _GLIBCXX_HOSTED +# define __glibcxx_sstream_from_string_view 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_sstream_from_string_view) +# define __cpp_lib_sstream_from_string_view
[PATCH v2] libstdc++: Implement stringstream from string_view [PR119741]
Change in V2: * apply all review comments * remove redundant drive-by "requires" on ctor from string allocator arg * check allocators are plumbed through -- >8 -- Implement PR libstdc++/119741 (P2495R3) Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view in places where the existing functions take a string. libstdc++-v3/ChangeLog: PR libstdc++/119741 * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/bits/version.def, include/bits/version.h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/3.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/2.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/4.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/2.cc: New tests. --- libstdc++-v3/include/bits/version.def | 11 +- libstdc++-v3/include/bits/version.h | 10 + libstdc++-v3/include/std/sstream | 174 ++-- .../27_io/basic_istringstream/cons/char/2.cc | 187 + .../27_io/basic_ostringstream/cons/char/4.cc | 186 + .../27_io/basic_stringbuf/cons/char/3.cc | 196 ++ .../27_io/basic_stringstream/cons/char/2.cc | 196 ++ 7 files changed, 941 insertions(+), 19 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/2.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 282667eabda..8172bcd4e26 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -649,7 +649,7 @@ ftms = { }; values = { v = 1; -/* For when there's no gthread. */ +// For when there is no gthread. cxxmin = 17; hosted = yes; gthread = no; @@ -1945,6 +1945,15 @@ ftms = { }; }; +ftms = { + name = sstream_from_string_view; + values = { +v = 202302; +cxxmin = 26; +hosted = yes; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index bb7c0479c72..b4b487fba92 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2174,4 +2174,14 @@ #endif /* !defined(__cpp_lib_modules) && defined(__glibcxx_want_modules) */ #undef __glibcxx_want_modules +#if !defined(__cpp_lib_sstream_from_string_view) +# if (__cplusplus > 202302L) && _GLIBCXX_HOSTED +# define __glibcxx_sstream_from_string_view 202302L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_sstream_from_string_view) +# define __cpp_lib_sstream_from_string_view 202302L +# endif +# endif +#endif /* !defined(__cpp_lib_sstream_from_string_view) && defined(__glibcxx_want_sstream_from_string_view) */ +#undef __glibcxx_want_sstream_from_string_view + #undef __glibcxx_want_all diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index ad0c16a91e8..f019eb1e9fc 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -38,9 +38,14 @@ #endif #include // iostream +#include #include #include +#ifdef __cpp_lib_sstream_from_string_view +# include // is_convertible_v +#endif + #include // allocator_traits, __allocator_like #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI @@ -52,8 +57,6 @@ # define _GLIBCXX_SSTREAM_ALWAYS_INLINE [[__gnu__::__always_inline__]] #endif - - namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -159,6 +162,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { __rhs._M_sync(const_cast(__rhs._M_string.data()), 0, 0); } #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI + // P0408 Efficient access to basic_stringbuf buffer explicit basic_stringbuf(const allocator_type& __a) : basic_stringbuf(ios_base::in | std::ios_base::out, __a) @@ -197,7 +201,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 | ios_base::out) : basic_stringbuf(__s, __mode, allocator_type{}) { } +#endif + +#ifdef __cpp_lib_sstream_from_string_view + template + explicit + basic_stringbuf(const _Tp& __t, ios_base::openmode __mode = ios_base::in | ios_base::out) + requires (is_convertible_v>) + : basic_stringbuf(__t, __mode, allocator_type{}) + { } + + template + basic_stringbuf(const _Tp& __t, const allocator_type& __a) + r
Reverted. (was Re: [PATCH v4] libstdc++: stringstream ctors from string_view [PR119741])
On 6/4/25 20:30, H.J. Lu wrote: On Wed, Jun 4, 2025 at 8:02 PM Jonathan Wakely wrote: On Thu, 29 May 2025 at 20:30, Nathan Myers wrote: Change in V4: * Rename tests to string_view.cc * Adapt tests to cons/wchar_t directories * Define symbol __cpp_lib_sstream_from_string_view as 202406 * Define symbol __glibcxx_want_sstream_from_string_view before version.h * Include version.h after other includes * No include type_traits * Drive-by comment moved to commit message * Each `explicit` on its own line * Run tests even when using old COW string Change in V3: * Comment that p2495 specifies a drive-by constraint omitted as redundant * Adjust whitespace to fit in 80 columns Change in V2: * Apply all review comments * Remove redundant drive-by "requires" on ctor from string allocator arg * Check allocators are plumbed through Looks great now, thanks for iterating on it. Please push to trunk (you'll probably need to rebase first, which will have a merge conflict in bits/version.h but just regenerating it again will resolve that). On Fedora 42/x86-64, I got FAIL: 27_io/basic_istringstream/cons/wchar_t/string_view.cc -std=gnu++17 (test for excess errors) Excess errors: /export/gnu/import/git/gitlab/x86-gcc-test/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/../char/string_view.cc:39: error: 'requires' only available with '-std=c++20' or '-fconcepts' [-Wtemplate-body] /export/gnu/import/git/gitlab/x86-gcc-test/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/../char/string_view.cc:39: error: expected ',' before '{' token [-Wtemplate-body] /export/gnu/import/git/gitlab/x86-gcc-test/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/../char/string_view.cc:39: warning: 'static_assert' with non-string message only available with '-std=c++2c' or '-std=gnu++2c' [-Wc++26-extensions] /export/gnu/import/git/gitlab/x86-gcc-test/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/../char/string_view.cc:39: error: expected primary-expression before '{' token [-Wtemplate-body] /export/gnu/import/git/gitlab/x86-gcc-test/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/../char/string_view.cc:39: error: expected ')' before '{' token [-Wtemplate-body] /export/gnu/import/git/gitlab/x86-gcc-test/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/../char/string_view.cc:41: error: 'requires' only available with '-std=c++20' or '-fconcepts' [-Wtemplate-body] /export/gnu/import/git/gitlab/x86-gcc-test/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/../char/string_view.cc:41: error: expected ',' before '{' token [-Wtemplate-body] Reverted a31e76a2643. -- >8 -- Implement PR libstdc++/119741 (P2495R3). Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view in places where the existing ctors and function take a string. Note this change omits the constraint applied to the istringstream constructor from string cited as a "drive-by" in P2495R3, as we have determined it is redundant. libstdc++-v3/ChangeLog: PR libstdc++/119741 * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/bits/version.def, include/bits/version.h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringbuf/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/wchar_t/string_view.cc: New tests. --- libstdc++-v3/include/bits/version.def | 11 +- libstdc++-v3/include/bits/version.h | 10 + libstdc++-v3/include/std/sstream | 198 +++-- .../cons/char/string_view.cc | 195 + .../cons/wchar_t/string_view.cc | 3 + .../cons/char/string_view.cc | 194 + .../cons/wchar_t/string_view.cc | 3 + .../basic_stringbuf/cons/char/string_view.cc | 205 ++ .../cons/wchar_t/string_view.cc | 3 + .../cons/char/string_view.cc
[PATCHv3] libstdc++: Add NTTP bind_front, -back, not_fn (P2714) [PR119744]
This should be close to ready. However, std::is_invocable and noexcept still fail oddly applied to the not_fp result. The remaining failing test cases in */nttp.cc, commented out, need careful examination to see whether they should be expecting different results given that the argument function object is necessarily const. Changes in v3: * NTTP functions bind_front, bind_back are self-contained. * No tuples: bind_front and bind_back return a simple lambda. * bind_front, _back with no arguments simply return the template parameter function. * Forwarded-argument passing is disciplined. * NTTP not_fn uses a helper struct with static op(). * Many more of tests that pass non-NTTP versions also pass Add non-type template parameter function-object/-pointer argument versions of bind_front, bind_back, and not_fn. libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads * testsuite/20_util/function_objects/bind_back/1.cc * testsuite/20_util/function_objects/bind_back/nttp.cc * testsuite/20_util/function_objects/bind_front/1.cc * testsuite/20_util/function_objects/bind_front/nttp.cc * testsuite/20_util/function_objects/not_fn/nttp.cc * testsuite/20_util/headers/functional/synopsis.cc --- libstdc++-v3/include/bits/version.def | 12 ++ libstdc++-v3/include/bits/version.h | 21 +- libstdc++-v3/include/std/functional | 137 - .../20_util/function_objects/bind_back/1.cc | 22 +-- .../function_objects/bind_back/nttp.cc| 186 ++ .../20_util/function_objects/bind_front/1.cc | 16 +- .../function_objects/bind_front/nttp.cc | 186 ++ .../20_util/function_objects/not_fn/nttp.cc | 102 ++ .../20_util/headers/functional/synopsis.cc| 21 ++ 9 files changed, 678 insertions(+), 25 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_back/nttp.cc create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_front/nttp.cc create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/not_fn/nttp.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 2f70a529927..7909a7b194a 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -463,6 +463,10 @@ ftms = { ftms = { name = not_fn; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201603; cxxmin = 17; @@ -776,6 +780,10 @@ ftms = { ftms = { name = bind_front; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201907; cxxmin = 20; @@ -784,6 +792,10 @@ ftms = { ftms = { name = bind_back; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 202202; cxxmin = 23; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 8e0ae682251..9721d1d23fe 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -511,7 +511,12 @@ #undef __glibcxx_want_make_from_tuple #if !defined(__cpp_lib_not_fn) -# if (__cplusplus >= 201703L) +# if (__cplusplus > 202302L) +# define __glibcxx_not_fn 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) +# define __cpp_lib_not_fn 202306L +# endif +# elif (__cplusplus >= 201703L) # define __glibcxx_not_fn 201603L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) # define __cpp_lib_not_fn 201603L @@ -866,7 +871,12 @@ #undef __glibcxx_want_atomic_value_initialization #if !defined(__cpp_lib_bind_front) -# if (__cplusplus >= 202002L) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_front 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) +# define __cpp_lib_bind_front 202306L +# endif +# elif (__cplusplus >= 202002L) # define __glibcxx_bind_front 201907L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) # define __cpp_lib_bind_front 201907L @@ -876,7 +886,12 @@ #undef __glibcxx_want_bind_front #if !defined(__cpp_lib_bind_back) -# if (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_back 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) +# define __cpp_lib_bind_back 202306L +# endif +# elif (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) # define __glibcxx_bind_back 202202L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) # define __cpp_lib_bind_back 202202L diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 307bcb95bcc..24d83097cb1 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std
[PATCH v2] libstdc++: construct bitset from string_view (P2697) [PR119742]
Changes in V2: * Generalize private member _M_check_initial_position for use with both string and string_view arguments. * Remove unnecessary #if guards for version and hostedness. * Remove redundant "std::" qualifications in new code. * Improve Doxygen source readability. * Clarify commit message text. * Fix ChangeLog style. Add a bitset constructor from string_view, per P2697. Fix existing tests that would fail to detect incorrect exception behavior. Argument checks that result in exceptions guarded by "#if HOSTED" are made unguarded because the functions called to throw just call terminate() in free-standing builds. Improve readability in Doxygen comments. Generalize a private member argument-checking function to work with string and string_view without mentioning either, obviating need for guards. The version.h symbol is not "hosted" because string_view, though not specified to be available in free-standing builds, is defined there and the feature is useful there. libstdc++-v3/ChangeLog: PR libstdc++/119742 * include/bits/version.def: Add preprocessor symbol. * include/bits/version.h: Add preprocessor symbol. * include/std/bitset: Add constructor. * testsuite/20_util/bitset/cons/1.cc: Fix. * testsuite/20_util/bitset/cons/6282.cc: Fix. * testsuite/20_util/bitset/cons/string_view.cc: Test new ctor. * testsuite/20_util/bitset/cons/string_view_wide.cc: Test new ctor. --- libstdc++-v3/include/bits/version.def | 8 ++ libstdc++-v3/include/bits/version.h | 10 ++ libstdc++-v3/include/std/bitset | 82 +++ .../testsuite/20_util/bitset/cons/1.cc| 1 + .../testsuite/20_util/bitset/cons/6282.cc | 5 +- .../20_util/bitset/cons/string_view.cc| 132 ++ .../20_util/bitset/cons/string_view_wide.cc | 8 ++ 7 files changed, 215 insertions(+), 31 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/string_view.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/string_view_wide.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index f4ba501c403..b89b287e8e8 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -2030,6 +2030,14 @@ ftms = { }; }; +ftms = { + name = bitset // ...construct from string_view + values = { +v = 202306; +cxxmin = 26; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index dc8ac07be16..a70a7ede68c 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2273,4 +2273,14 @@ #endif /* !defined(__cpp_lib_exception_ptr_cast) && defined(__glibcxx_want_exception_ptr_cast) */ #undef __glibcxx_want_exception_ptr_cast +#if !defined(__cpp_lib_bitset) +# if (__cplusplus > 202302L) +# define __glibcxx_bitset 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bitset) +# define __cpp_lib_bitset 202306L +# endif +# endif +#endif /* !defined(__cpp_lib_bitset) && defined(__glibcxx_want_bitset) */ +#undef __glibcxx_bitset + #undef __glibcxx_want_all diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index 8b5d270c2a9..1c1e1670c33 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -61,8 +61,13 @@ #endif #define __glibcxx_want_constexpr_bitset +#define __glibcxx_want_bitset // ...construct from string_view #include +#ifdef __cpp_lib_bitset // ...construct from string_view +# include +#endif + #define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__) #define _GLIBCXX_BITSET_WORDS(__n) \ ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \ @@ -752,7 +757,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * (Note that %bitset does @e not meet the formal requirements of a * container. Mainly, it lacks iterators.) * - * The template argument, @a Nb, may be any non-negative number, + * The template argument, `Nb`, may be any non-negative number, * specifying the number of bits (e.g., "0", "12", "1024*1024"). * * In the general unoptimized case, storage is allocated in word-sized @@ -816,28 +821,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typedef _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)> _Base; typedef unsigned long _WordT; -#if _GLIBCXX_HOSTED - template - _GLIBCXX23_CONSTEXPR - void - _M_check_initial_position(const std::basic_string<_CharT, _Traits, _Alloc>& __s, - size_t __position) const + template + _GLIBCXX23_CONSTEXPR void + _M_check_initial_position( + const _Str& __s, typename _Str::size_type __position) const { if (__position > __s.size()) - __throw_out_of_range_fmt(__N("bitset::bitset: __position " -
[SNAPv3] libstdc++: Add NTTP bind_front, _back (P2714) [PR119744]
This is a snapshot of work on P2714 "Bind front and back to NTTP callables", posted for reference. Questions: 1. Jonathan asks if __type_forward_like_t does the same job as __like_t in bits/move.h. 2. Could the "if constexpr" statements be better expressed as requires clauses via the A=>B == !A||B identity? libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads --- libstdc++-v3/include/bits/version.def | 12 +++ libstdc++-v3/include/bits/version.h | 21 - libstdc++-v3/include/std/functional | 124 +- 3 files changed, 153 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 5d5758bf203..8ab9a7207e7 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -463,6 +463,10 @@ ftms = { ftms = { name = not_fn; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201603; cxxmin = 17; @@ -776,6 +780,10 @@ ftms = { ftms = { name = bind_front; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201907; cxxmin = 20; @@ -784,6 +792,10 @@ ftms = { ftms = { name = bind_back; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 202202; cxxmin = 23; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 2b00e8419b3..c204ae3c48c 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -511,7 +511,12 @@ #undef __glibcxx_want_make_from_tuple #if !defined(__cpp_lib_not_fn) -# if (__cplusplus >= 201703L) +# if (__cplusplus > 202302L) +# define __glibcxx_not_fn 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) +# define __cpp_lib_not_fn 202306L +# endif +# elif (__cplusplus >= 201703L) # define __glibcxx_not_fn 201603L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) # define __cpp_lib_not_fn 201603L @@ -866,7 +871,12 @@ #undef __glibcxx_want_atomic_value_initialization #if !defined(__cpp_lib_bind_front) -# if (__cplusplus >= 202002L) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_front 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) +# define __cpp_lib_bind_front 202306L +# endif +# elif (__cplusplus >= 202002L) # define __glibcxx_bind_front 201907L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) # define __cpp_lib_bind_front 201907L @@ -876,7 +886,12 @@ #undef __glibcxx_want_bind_front #if !defined(__cpp_lib_bind_back) -# if (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_back 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) +# define __cpp_lib_bind_back 202306L +# endif +# elif (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) # define __glibcxx_bind_back 202202L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) # define __cpp_lib_bind_back 202202L diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 307bcb95bcc..21f0b1cb2d5 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -940,7 +940,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_bound_args(std::forward<_Args>(__args)...) { static_assert(sizeof...(_Args) == sizeof...(_BoundArgs)); } -#if __cpp_explicit_this_parameter +#ifdef __cpp_explicit_this_parameter template constexpr invoke_result_t<__like_t<_Self, _Fd>, __like_t<_Self, _BoundArgs>..., _CallArgs...> @@ -1218,8 +1218,130 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return _Not_fn>{std::forward<_Fn>(__fn), 0}; } +#if __cpp_lib_not_fn >= 202306 + /** Wrap a function type to create a function object that negates its result. + * + * The function template `std::not_fn` creates a "forwarding call wrapper", + * which is a function object that when called forwards its arguments to + * its invocable template argument. + * + * The result of invoking the wrapper is the negation (using `!`) of + * the wrapped function object. + * + * @ingroup functors + * @since C++26 + */ + template + constexpr auto + not_fn() noexcept + { +using _Fn = decltype(__fn); +if constexpr (is_pointer_v<_Fn> or is_member_pointer_v<_Fn>) { + static_assert(__fn != nullptr); +} +return [] (_Tp&&... __call_args) + noexcept(is_nothrow_invocable_v<_Fn, _Tp...>) + -> invoke_result_t<_Fn, _Tp...> +{ + return !invoke(__fn, forward<_Tp>(__call_args)...); +}; + } +#endif // __cpp_lib_not_fn >= 202306 +#endif // __cpp_lib_not_fn + +#if __cpp_lib_bind_front >= 202306 || __cpp_li
[PATCH] libstdc++: provide debug impl of P2697 ctor [PR119742]
This adds the new bitset constructor from string_view defined in P2697 to the debug version of the type. libstdc++-v3/Changelog: PR libstdc++/119742 * include/debug/bitset: Add new ctor. --- libstdc++-v3/include/debug/bitset | 12 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/debug/bitset b/libstdc++-v3/include/debug/bitset index ad9b7b5c4b0..43656a4efd3 100644 --- a/libstdc++-v3/include/debug/bitset +++ b/libstdc++-v3/include/debug/bitset @@ -164,6 +164,18 @@ namespace __debug _CharT __zero, _CharT __one = _CharT('1')) : _Base(__str, __pos, __n, __zero, __one) { } +#ifdef __cpp_lib_bitset // ... from string_view + template + constexpr explicit + bitset(std::basic_string_view<_CharT, _Traits> __s, + std::basic_string_view<_CharT, _Traits>::size_type __position = 0, + std::basic_string_view<_CharT, _Traits>::size_type __n = + std::basic_string_view<_CharT, _Traits>::npos, + _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) + : _Base(__s.data() + std::min(__position, __s.size()), + std::min(__n, __s.size()), __zero, __one) { } +#endif + _GLIBCXX23_CONSTEXPR bitset(const _Base& __x) : _Base(__x) { } -- 2.50.0
[SNAPv4] libstdc++: Add NTTP bind_front, -back, not_fn (P2714) [PR119744]
This is a snapshot of work in progress, for reference. bind_front(...) is uglified directly from the sample implementation in P2714, at include/std/functional:1284 . Test failures: bind_front/1.cc:53: error: static assertion failed bind_front/1.cc:57: error: static assertion failed bind_front/1.cc:214: error: static assertion failed bind_front/1.cc:215: error: static assertion failed bind_front/1.cc:216: required from here functional:1301: error: invalid conversion from 'std::invoke_result_t&, void*&>' {aka 'void*'} to 'int' [-fpermissive] [... etc. ] Also complains about 218, 220, 231, 233-6, 264, 267 libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads * testsuite/20_util/function_objects/bind_front/1.cc --- libstdc++-v3/include/bits/version.def | 12 ++ libstdc++-v3/include/bits/version.h | 21 ++- libstdc++-v3/include/std/functional | 124 +- .../20_util/function_objects/bind_front/1.cc | 103 ++- 4 files changed, 278 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 5d5758bf203..8ab9a7207e7 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -463,6 +463,10 @@ ftms = { ftms = { name = not_fn; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201603; cxxmin = 17; @@ -776,6 +780,10 @@ ftms = { ftms = { name = bind_front; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201907; cxxmin = 20; @@ -784,6 +792,10 @@ ftms = { ftms = { name = bind_back; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 202202; cxxmin = 23; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 2b00e8419b3..c204ae3c48c 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -511,7 +511,12 @@ #undef __glibcxx_want_make_from_tuple #if !defined(__cpp_lib_not_fn) -# if (__cplusplus >= 201703L) +# if (__cplusplus > 202302L) +# define __glibcxx_not_fn 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) +# define __cpp_lib_not_fn 202306L +# endif +# elif (__cplusplus >= 201703L) # define __glibcxx_not_fn 201603L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) # define __cpp_lib_not_fn 201603L @@ -866,7 +871,12 @@ #undef __glibcxx_want_atomic_value_initialization #if !defined(__cpp_lib_bind_front) -# if (__cplusplus >= 202002L) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_front 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) +# define __cpp_lib_bind_front 202306L +# endif +# elif (__cplusplus >= 202002L) # define __glibcxx_bind_front 201907L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) # define __cpp_lib_bind_front 201907L @@ -876,7 +886,12 @@ #undef __glibcxx_want_bind_front #if !defined(__cpp_lib_bind_back) -# if (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_back 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) +# define __cpp_lib_bind_back 202306L +# endif +# elif (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) # define __glibcxx_bind_back 202202L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) # define __cpp_lib_bind_back 202202L diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 307bcb95bcc..21f0b1cb2d5 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -940,7 +940,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_bound_args(std::forward<_Args>(__args)...) { static_assert(sizeof...(_Args) == sizeof...(_BoundArgs)); } -#if __cpp_explicit_this_parameter +#ifdef __cpp_explicit_this_parameter template constexpr invoke_result_t<__like_t<_Self, _Fd>, __like_t<_Self, _BoundArgs>..., _CallArgs...> @@ -1218,8 +1218,130 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return _Not_fn>{std::forward<_Fn>(__fn), 0}; } +#if __cpp_lib_not_fn >= 202306 + /** Wrap a function type to create a function object that negates its result. + * + * The function template `std::not_fn` creates a "forwarding call wrapper", + * which is a function object that when called forwards its arguments to + * its invocable template argument. + * + * The result of invoking the wrapper is the negation (using `!`) of + * the wrapped function object. + * + * @ingroup functors + * @since C++26 + */ + template + constexpr auto + not_fn() noexcept + { +using _Fn = decltyp
[SNAPv2] libstdc++: Add NTTP bind_front, _back (P2714) [PR119744]
This is a snapshot of work on P2714 "Bind front and back to NTTP callables", posted for reference. Not tested. libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads --- libstdc++-v3/include/bits/version.def | 6 +- libstdc++-v3/include/bits/version.h | 18 ++--- libstdc++-v3/include/std/functional | 96 ++- 3 files changed, 107 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index b89b287e8e8..f8ccfaeb8c3 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -464,7 +464,7 @@ ftms = { ftms = { name = not_fn; values = { -v = 201603; +v = 202306; cxxmin = 17; }; }; @@ -777,7 +777,7 @@ ftms = { ftms = { name = bind_front; values = { -v = 201907; +v = 202306 cxxmin = 20; }; }; @@ -785,7 +785,7 @@ ftms = { ftms = { name = bind_back; values = { -v = 202202; +v = 202306; cxxmin = 23; extra_cond = "__cpp_explicit_this_parameter"; }; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index a70a7ede68c..52e6ae2d9b8 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -511,10 +511,10 @@ #undef __glibcxx_want_make_from_tuple #if !defined(__cpp_lib_not_fn) -# if (__cplusplus >= 201703L) -# define __glibcxx_not_fn 201603L +# if (__cplusplus >= 202306L) +# define __glibcxx_not_fn 202306L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) -# define __cpp_lib_not_fn 201603L +# define __cpp_lib_not_fn 202306L # endif # endif #endif /* !defined(__cpp_lib_not_fn) && defined(__glibcxx_want_not_fn) */ @@ -866,20 +866,20 @@ #undef __glibcxx_want_atomic_value_initialization #if !defined(__cpp_lib_bind_front) -# if (__cplusplus >= 202002L) -# define __glibcxx_bind_front 201907L +# if (__cplusplus >= 202306L) +# define __glibcxx_bind_front 202306L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) -# define __cpp_lib_bind_front 201907L +# define __cpp_lib_bind_front 202306L # endif # endif #endif /* !defined(__cpp_lib_bind_front) && defined(__glibcxx_want_bind_front) */ #undef __glibcxx_want_bind_front #if !defined(__cpp_lib_bind_back) -# if (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) -# define __glibcxx_bind_back 202202L +# if (__cplusplus >= 202306L) && (__cpp_explicit_this_parameter) +# define __glibcxx_bind_back 202306L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) -# define __cpp_lib_bind_back 202202L +# define __cpp_lib_bind_back 202306L # endif # endif #endif /* !defined(__cpp_lib_bind_back) && defined(__glibcxx_want_bind_back) */ diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 307bcb95bcc..c317d471350 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -940,7 +940,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_bound_args(std::forward<_Args>(__args)...) { static_assert(sizeof...(_Args) == sizeof...(_BoundArgs)); } -#if __cpp_explicit_this_parameter +#ifdef __cpp_explicit_this_parameter template constexpr invoke_result_t<__like_t<_Self, _Fd>, __like_t<_Self, _BoundArgs>..., _CallArgs...> @@ -1049,6 +1049,97 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Bind_front_t<_Fn, _Args...>(0, std::forward<_Fn>(__fn), std::forward<_Args>(__args)...); } + +#if __cpp_lib_bind_front >= 202306 + + template + struct __copy_const : conditional, const _U, _U> {}; + + template, _U>::type> + + struct __copy_value_category +: conditional, _X&, _X&&> + {}; + + template + struct __type_forward_like : __copy_value_category<_T, remove_reference_t<_U>> + {}; + + template + using __type_forward_like_t = __type_forward_like<_T, _U>::type; + + /** Create call wrapper by partial application of arguments to function. + * + * The result of `std::bind_front(args...)` is a function object that + * stores `f` and the bound arguments, `args...`. When that function + * object is invoked with `call_args...` it returns the result of calling + * `f(args..., call_args...)`. + * + * @since C++26 + */ + + template + constexpr auto + bind_front(_Args&&... __args) +requires ( + (is_constructible_v, _Args> and ...) and + (is_move_constructible_v> and ...)) + { +using _Fn = decltype(__fn); +if constexpr (is_pointer_v<_Fn> or is_member_pointer_v<_Fn>) { + static_assert(__fn != nullptr); +} +return [... __bound_args(std::forward<_Args>(__args))]< +typename _Self, typename... _T> + (this _Self&&, _T&&... __call_args)
[SNAP] libstdc++: Add NTTP bind_front, _back (P2714) [PR119744]
This is a snapshot of work on P2714 "Bind front and back to NTTP callables", posted for reference. Not tested. libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads --- libstdc++-v3/include/bits/version.def | 6 +- libstdc++-v3/include/bits/version.h | 18 ++--- libstdc++-v3/include/std/functional | 94 ++- 3 files changed, 105 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index b89b287e8e8..f8ccfaeb8c3 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -464,7 +464,7 @@ ftms = { ftms = { name = not_fn; values = { -v = 201603; +v = 202306; cxxmin = 17; }; }; @@ -777,7 +777,7 @@ ftms = { ftms = { name = bind_front; values = { -v = 201907; +v = 202306 cxxmin = 20; }; }; @@ -785,7 +785,7 @@ ftms = { ftms = { name = bind_back; values = { -v = 202202; +v = 202306; cxxmin = 23; extra_cond = "__cpp_explicit_this_parameter"; }; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index a70a7ede68c..52e6ae2d9b8 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -511,10 +511,10 @@ #undef __glibcxx_want_make_from_tuple #if !defined(__cpp_lib_not_fn) -# if (__cplusplus >= 201703L) -# define __glibcxx_not_fn 201603L +# if (__cplusplus >= 202306L) +# define __glibcxx_not_fn 202306L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) -# define __cpp_lib_not_fn 201603L +# define __cpp_lib_not_fn 202306L # endif # endif #endif /* !defined(__cpp_lib_not_fn) && defined(__glibcxx_want_not_fn) */ @@ -866,20 +866,20 @@ #undef __glibcxx_want_atomic_value_initialization #if !defined(__cpp_lib_bind_front) -# if (__cplusplus >= 202002L) -# define __glibcxx_bind_front 201907L +# if (__cplusplus >= 202306L) +# define __glibcxx_bind_front 202306L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) -# define __cpp_lib_bind_front 201907L +# define __cpp_lib_bind_front 202306L # endif # endif #endif /* !defined(__cpp_lib_bind_front) && defined(__glibcxx_want_bind_front) */ #undef __glibcxx_want_bind_front #if !defined(__cpp_lib_bind_back) -# if (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) -# define __glibcxx_bind_back 202202L +# if (__cplusplus >= 202306L) && (__cpp_explicit_this_parameter) +# define __glibcxx_bind_back 202306L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) -# define __cpp_lib_bind_back 202202L +# define __cpp_lib_bind_back 202306L # endif # endif #endif /* !defined(__cpp_lib_bind_back) && defined(__glibcxx_want_bind_back) */ diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 307bcb95bcc..d960712480e 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -940,7 +940,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_bound_args(std::forward<_Args>(__args)...) { static_assert(sizeof...(_Args) == sizeof...(_BoundArgs)); } -#if __cpp_explicit_this_parameter +#ifdef __cpp_explicit_this_parameter template constexpr invoke_result_t<__like_t<_Self, _Fd>, __like_t<_Self, _BoundArgs>..., _CallArgs...> @@ -1049,6 +1049,98 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Bind_front_t<_Fn, _Args...>(0, std::forward<_Fn>(__fn), std::forward<_Args>(__args)...); } + +#if __cpp_lib_bind_front >= 202306 + + template + struct __copy_const : conditional, const _U, _U> {}; + + template, _U>::type> + + struct __copy_value_category +: conditional, _X&, _X&&> + {}; + + template + struct __type_forward_like : __copy_value_category<_T, remove_reference_t<_U>> + {}; + + template + using __type_forward_like_t = __type_forward_like<_T, _U>::type; + + /** Create call wrapper by partial application of arguments to function. + * + * The result of `std::bind_front(args...)` is a function object that + * stores `f` and the bound arguments, `args...`. When that function + * object is invoked with `call_args...` it returns the result of calling + * `f(args..., call_args...)`. + * + * @since C++26 + */ + + template + constexpr auto + bind_front(_Args&&... __args) +requires ( + (is_constructible_v..., _Args> and ...) and + (is_move_constructible_v...> and ...)) + { +using _Fn = decltype(__fn); +if constexpr (is_pointer_v<_Fn> or is_member_pointer_v<_Fn>) { + static_assert(__fn != nullptr); +} +return [... __bound_args(std::forward<_Args>(__args))]< +typename _Self, typename... _T> + (this _Self&&, _T&&... __call
[PATCH] libstdc++: construct bitset from string_view (P2697) [PR119742]
Add a bitset constructor from string_view, with other arguments matching the constructor from string. Test in ways that exercise code paths not checked in existing tests for other constructors. Fix existing tests that would fail to detect incorrect exception behavior. libstdc++-v3/ChangeLog: PR libstdc++/119742 * include/bits/version.def: new preprocessor symbol * include/bits/version.h: new preprocessor symbol * include/std/bitset: new constructor * testsuite/20_util/bitset/cons/1.cc: fix * testsuite/20_util/bitset/cons/6282.cc: fix * testsuite/20_util/bitset/cons/string_view.cc: new tests * testsuite/20_util/bitset/cons/string_view_wide.cc: new tests --- libstdc++-v3/include/bits/version.def | 8 ++ libstdc++-v3/include/bits/version.h | 10 ++ libstdc++-v3/include/std/bitset | 49 +++ .../testsuite/20_util/bitset/cons/1.cc| 1 + .../testsuite/20_util/bitset/cons/6282.cc | 5 +- .../20_util/bitset/cons/string_view.cc| 132 ++ .../20_util/bitset/cons/string_view_wide.cc | 8 ++ 7 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/string_view.cc create mode 100644 libstdc++-v3/testsuite/20_util/bitset/cons/string_view_wide.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 880586e9126..d82585e1238 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -2012,6 +2012,14 @@ ftms = { }; }; +ftms = { + name = bitset // ...construct from string_view + values = { +v = 202306; +cxxmin = 26; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 4300adb2276..c0d3cbe623f 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2253,4 +2253,14 @@ #endif /* !defined(__cpp_lib_sstream_from_string_view) && defined(__glibcxx_want_sstream_from_string_view) */ #undef __glibcxx_want_sstream_from_string_view +#if !defined(__cpp_lib_bitset) +# if (__cplusplus > 202302L) +# define __glibcxx_bitset 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bitset) +# define __cpp_lib_bitset 202306L +# endif +# endif +#endif /* !defined(__cpp_lib_bitset) && defined(__glibcxx_want_bitset) */ +#undef __glibcxx_bitset + #undef __glibcxx_want_all diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index 8b5d270c2a9..f4947902384 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -61,8 +61,13 @@ #endif #define __glibcxx_want_constexpr_bitset +#define __glibcxx_want_bitset // ...construct from string_view #include +#ifdef __cpp_lib_bitset // ...construct from string_view +# include +#endif + #define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__) #define _GLIBCXX_BITSET_WORDS(__n) \ ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \ @@ -831,6 +836,24 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } #endif // HOSTED +#ifdef __cpp_lib_bitset + template + constexpr void + _M_check_initial_position( + std::basic_string_view<_CharT, _Traits> __s, + typename std::basic_string_view<_CharT, _Traits>::size_type __position + ) const + { +# if _GLIBCXX_HOSTED + if (__position > __s.size()) + __throw_out_of_range_fmt(__N("bitset::bitset: __position " + "(which is %zu) > __s.size() " + "(which is %zu)"), + __position, __s.size()); +# endif + } +#endif + _GLIBCXX23_CONSTEXPR void _M_check(size_t __position, const char *__s) const { @@ -1008,6 +1031,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } #endif // HOSTED +#ifdef __cpp_lib_bitset + /** + * Use a subset of a string view. + * @param __s A string_view of a sequence of @a 0 and @a 1 characters. + * @param __position Index of the first character in @a __s to use. + * @param __nThe maximum number of characters from @a __s to use. + * @throw std::out_of_range If @a __position is bigger the size + * of @a __s. + * @throw std::invalid_argument If a character appears in the string + * which is neither @a 0 nor @a 1. + */ + template + constexpr explicit + bitset(std::basic_string_view<_CharT, _Traits> __s, + std::basic_string_view<_CharT, _Traits>::size_type __position = 0, + std::basic_string_view<_CharT, _Traits>::size_type __n = + std::basic_string_view<_CharT, _Traits>::npos, + _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) + : _Base() + { +
[PATCH] libstdc++: make range view ctors explicit (P2711) [PR119744]
Make range view constructors explicit, per P2711. Technically, this is a breaking change, but it is unlikely to break any production code, as reliance on non-explicit construction is unidiomatic.. libstdc++-v3/ChangeLog PR libstdc++/119744 * include/std/ranges: view ctors become explicit --- libstdc++-v3/include/std/ranges | 32 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 210ac8274fc..f764aa7512e 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -660,7 +660,7 @@ namespace ranges : _M_value(__value) { } - constexpr + constexpr explicit iota_view(type_identity_t<_Winc> __value, type_identity_t<_Bound> __bound) : _M_value(__value), _M_bound(__bound) @@ -669,19 +669,19 @@ namespace ranges __glibcxx_assert( bool(__value <= __bound) ); } - constexpr + constexpr explicit iota_view(_Iterator __first, _Iterator __last) requires same_as<_Winc, _Bound> : iota_view(__first._M_value, __last._M_value) { } - constexpr + constexpr explicit iota_view(_Iterator __first, unreachable_sentinel_t __last) requires same_as<_Bound, unreachable_sentinel_t> : iota_view(__first._M_value, __last) { } - constexpr + constexpr explicit iota_view(_Iterator __first, _Sentinel __last) requires (!same_as<_Winc, _Bound>) && (!same_as<_Bound, unreachable_sentinel_t>) : iota_view(__first._M_value, __last._M_bound) @@ -1811,7 +1811,7 @@ namespace views::__adaptor && default_initializable<_Pred>) = default; - constexpr + constexpr explicit filter_view(_Vp __base, _Pred __pred) : _M_base(std::move(__base)), _M_pred(std::move(__pred)) { } @@ -2188,7 +2188,7 @@ namespace views::__adaptor && default_initializable<_Fp>) = default; - constexpr + constexpr explicit transform_view(_Vp __base, _Fp __fun) : _M_base(std::move(__base)), _M_fun(std::move(__fun)) { } @@ -2323,7 +2323,7 @@ namespace views::__adaptor public: take_view() requires default_initializable<_Vp> = default; - constexpr + constexpr explicit take_view(_Vp __base, range_difference_t<_Vp> __count) : _M_base(std::move(__base)), _M_count(std::move(__count)) { } @@ -2562,7 +2562,7 @@ namespace views::__adaptor && default_initializable<_Pred>) = default; - constexpr + constexpr explicit take_while_view(_Vp __base, _Pred __pred) : _M_base(std::move(__base)), _M_pred(std::move(__pred)) { } @@ -2650,7 +2650,7 @@ namespace views::__adaptor public: drop_view() requires default_initializable<_Vp> = default; - constexpr + constexpr explicit drop_view(_Vp __base, range_difference_t<_Vp> __count) : _M_base(std::move(__base)), _M_count(__count) { __glibcxx_assert(__count >= 0); } @@ -2804,7 +2804,7 @@ namespace views::__adaptor && default_initializable<_Pred>) = default; - constexpr + constexpr explicit drop_while_view(_Vp __base, _Pred __pred) : _M_base(std::move(__base)), _M_pred(std::move(__pred)) { } @@ -3641,7 +3641,7 @@ namespace views::__adaptor && default_initializable<_Pattern>) = default; - constexpr + constexpr explicit lazy_split_view(_Vp __base, _Pattern __pattern) : _M_base(std::move(__base)), _M_pattern(std::move(__pattern)) { } @@ -3649,7 +3649,7 @@ namespace views::__adaptor template requires constructible_from<_Vp, views::all_t<_Range>> && constructible_from<_Pattern, single_view>> - constexpr + constexpr explicit lazy_split_view(_Range&& __r, range_value_t<_Range> __e) : _M_base(views::all(std::forward<_Range>(__r))), _M_pattern(views::single(std::move(__e))) @@ -3766,7 +3766,7 @@ namespace views::__adaptor && default_initializable<_Pattern>) = default; -constexpr +constexpr explicit split_view(_Vp __base, _Pattern __pattern) : _M_base(std::move(__base)), _M_pattern(std::move(__pattern)) { } @@ -3774,7 +3774,7 @@ namespace views::__adaptor template requires constructible_from<_Vp, views::all_t<_Range>> && constructible_from<_Pattern, single_view>> -constexpr +constexpr explicit split_view(_Range&& __r, range_value_t<_Range> __e) : _M_base(views::all(std::forward<_Range>(__r))), _M_pattern(views::single(std::move(__e))) @@ -7295,7 +7295,7 @@ namespace views::__adaptor
[PATCH] libstdc++: Add NTTP bind_front, -back, not_fn (P2714) [PR119744]
[Note: many of the tests for the original versions do not make sense, require different outcomes, or otherwise fail on the new versions for reasons not obvious.] Add non-type template parameter function-object/-pointer argument versions of bind_front, bind_back, and not_fn as defined in P2714R1. libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads * testsuite/20_util/function_objects/bind_back/1.cc * testsuite/20_util/function_objects/bind_back/nttp.cc * testsuite/20_util/function_objects/bind_front/1.cc * testsuite/20_util/function_objects/bind_front/nttp.cc * testsuite/20_util/function_objects/not_fn/nttp.cc * testsuite/20_util/headers/functional/synopsis.cc --- libstdc++-v3/include/bits/version.def | 12 ++ libstdc++-v3/include/bits/version.h | 21 +- libstdc++-v3/include/std/functional | 124 +++- .../20_util/function_objects/bind_back/1.cc | 22 +-- .../function_objects/bind_back/nttp.cc| 186 ++ .../20_util/function_objects/bind_front/1.cc | 16 +- .../function_objects/bind_front/nttp.cc | 185 + .../20_util/function_objects/not_fn/nttp.cc | 97 + .../20_util/headers/functional/synopsis.cc| 22 +++ 9 files changed, 662 insertions(+), 23 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_back/nttp.cc create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_front/nttp.cc create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/not_fn/nttp.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 5d5758bf203..8ab9a7207e7 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -463,6 +463,10 @@ ftms = { ftms = { name = not_fn; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201603; cxxmin = 17; @@ -776,6 +780,10 @@ ftms = { ftms = { name = bind_front; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201907; cxxmin = 20; @@ -784,6 +792,10 @@ ftms = { ftms = { name = bind_back; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 202202; cxxmin = 23; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 2b00e8419b3..c204ae3c48c 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -511,7 +511,12 @@ #undef __glibcxx_want_make_from_tuple #if !defined(__cpp_lib_not_fn) -# if (__cplusplus >= 201703L) +# if (__cplusplus > 202302L) +# define __glibcxx_not_fn 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) +# define __cpp_lib_not_fn 202306L +# endif +# elif (__cplusplus >= 201703L) # define __glibcxx_not_fn 201603L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) # define __cpp_lib_not_fn 201603L @@ -866,7 +871,12 @@ #undef __glibcxx_want_atomic_value_initialization #if !defined(__cpp_lib_bind_front) -# if (__cplusplus >= 202002L) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_front 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) +# define __cpp_lib_bind_front 202306L +# endif +# elif (__cplusplus >= 202002L) # define __glibcxx_bind_front 201907L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) # define __cpp_lib_bind_front 201907L @@ -876,7 +886,12 @@ #undef __glibcxx_want_bind_front #if !defined(__cpp_lib_bind_back) -# if (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_back 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) +# define __cpp_lib_bind_back 202306L +# endif +# elif (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) # define __glibcxx_bind_back 202202L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) # define __cpp_lib_bind_back 202202L diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 307bcb95bcc..21f0b1cb2d5 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -940,7 +940,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_bound_args(std::forward<_Args>(__args)...) { static_assert(sizeof...(_Args) == sizeof...(_BoundArgs)); } -#if __cpp_explicit_this_parameter +#ifdef __cpp_explicit_this_parameter template constexpr invoke_result_t<__like_t<_Self, _Fd>, __like_t<_Self, _BoundArgs>..., _CallArgs...> @@ -1218,8 +1218,130 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return _Not_fn>{std::forward<_Fn>(__fn), 0}; } +#if __cpp_lib
[PATCHv2] libstdc++: Add NTTP bind_front, -back, not_fn (P2714) [PR119744]
* I rewrote the implementation to more closely resemble the non-NTTP version, and fix the various noexcept and requires omissions. * I don't understand what "a separate type for single argument case, that correspond to function_ref nontype, ptr/ref constructor" means, but I did make no-bound-arguments overloads. * P2714R1 has "Mandates: If is_pointer_v || is_member_pointer_v is true, then f != nullptr is true." This seems to require the "if constexpr" statements as written. * Some of the tests have results that differ from the non-NTTP results. Some differences are a consequence of different const qualification, as the argument callable is necessarily const. Others I don't understand, e.g. std::invocable_v reporting a call would work, where actually invoking it fails. Differences from the non-NTTP */1.cc tests are commented in */nttp.cc . Add non-type template parameter function-object/-pointer argument versions of bind_front, bind_back, and not_fn. libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads * testsuite/20_util/function_objects/bind_back/1.cc * testsuite/20_util/function_objects/bind_back/nttp.cc * testsuite/20_util/function_objects/bind_front/1.cc * testsuite/20_util/function_objects/bind_front/nttp.cc * testsuite/20_util/function_objects/not_fn/nttp.cc * testsuite/20_util/headers/functional/synopsis.cc --- libstdc++-v3/include/bits/version.def | 12 + libstdc++-v3/include/bits/version.h | 21 +- libstdc++-v3/include/std/functional | 230 +- .../20_util/function_objects/bind_back/1.cc | 22 +- .../function_objects/bind_back/nttp.cc| 191 +++ .../20_util/function_objects/bind_front/1.cc | 16 +- .../function_objects/bind_front/nttp.cc | 188 ++ .../20_util/function_objects/not_fn/nttp.cc | 101 .../20_util/headers/functional/synopsis.cc| 21 ++ 9 files changed, 778 insertions(+), 24 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_back/nttp.cc create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_front/nttp.cc create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/not_fn/nttp.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 2f70a529927..7909a7b194a 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -463,6 +463,10 @@ ftms = { ftms = { name = not_fn; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201603; cxxmin = 17; @@ -776,6 +780,10 @@ ftms = { ftms = { name = bind_front; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201907; cxxmin = 20; @@ -784,6 +792,10 @@ ftms = { ftms = { name = bind_back; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 202202; cxxmin = 23; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 8e0ae682251..9721d1d23fe 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -511,7 +511,12 @@ #undef __glibcxx_want_make_from_tuple #if !defined(__cpp_lib_not_fn) -# if (__cplusplus >= 201703L) +# if (__cplusplus > 202302L) +# define __glibcxx_not_fn 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) +# define __cpp_lib_not_fn 202306L +# endif +# elif (__cplusplus >= 201703L) # define __glibcxx_not_fn 201603L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) # define __cpp_lib_not_fn 201603L @@ -866,7 +871,12 @@ #undef __glibcxx_want_atomic_value_initialization #if !defined(__cpp_lib_bind_front) -# if (__cplusplus >= 202002L) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_front 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) +# define __cpp_lib_bind_front 202306L +# endif +# elif (__cplusplus >= 202002L) # define __glibcxx_bind_front 201907L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) # define __cpp_lib_bind_front 201907L @@ -876,7 +886,12 @@ #undef __glibcxx_want_bind_front #if !defined(__cpp_lib_bind_back) -# if (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_back 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) +# define __cpp_lib_bind_back 202306L +# endif +# elif (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) # define __glibcxx_bind_back 202202L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) # define __cpp_lib_bind_back 202202L diff --git a/libstdc++-v3/include/std/functi
[PATCHv4] libstdc++: Add NTTP bind_front, -back, not_fn (P2714) [PR119744]
This should be close to ready. However, std::is_invocable and noexcept still fail oddly applied to the not_fp result. The remaining failing test cases in */nttp.cc, commented out, need careful examination to see whether they should be expecting different results given that the argument function object is necessarily const. Changes in v4: * For the no-bound-arguments case, bind_front and bind_back both return a zero-size _BindFn_t with static operator(). * For the normal case, the lambda functions returned are declared to yield std::invoke_result_t<> instead of decltype(auto), which produces different test outcomes. Changes in v3: * NTTP functions bind_front, bind_back are self-contained. * No tuples: bind_front and bind_back return a simple lambda. * bind_front, _back with no arguments simply return the template parameter function. * Forwarded-argument passing is disciplined. * NTTP not_fn uses a helper struct with static op(). * Many more of tests that pass non-NTTP versions also pass Add non-type template parameter function-object/-pointer argument versions of bind_front, bind_back, and not_fn. libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads * testsuite/20_util/function_objects/bind_back/1.cc * testsuite/20_util/function_objects/bind_back/nttp.cc * testsuite/20_util/function_objects/bind_front/1.cc * testsuite/20_util/function_objects/bind_front/nttp.cc * testsuite/20_util/function_objects/not_fn/nttp.cc * testsuite/20_util/headers/functional/synopsis.cc --- libstdc++-v3/include/bits/version.def | 12 + libstdc++-v3/include/bits/version.h | 21 +- libstdc++-v3/include/std/functional | 159 - .../20_util/function_objects/bind_back/1.cc | 22 +- .../function_objects/bind_back/nttp.cc| 224 ++ .../20_util/function_objects/bind_front/1.cc | 16 +- .../function_objects/bind_front/nttp.cc | 218 + .../20_util/function_objects/not_fn/nttp.cc | 113 + .../20_util/headers/functional/synopsis.cc| 21 ++ 9 files changed, 781 insertions(+), 25 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_back/nttp.cc create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_front/nttp.cc create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/not_fn/nttp.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 2f70a529927..7909a7b194a 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -463,6 +463,10 @@ ftms = { ftms = { name = not_fn; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201603; cxxmin = 17; @@ -776,6 +780,10 @@ ftms = { ftms = { name = bind_front; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 201907; cxxmin = 20; @@ -784,6 +792,10 @@ ftms = { ftms = { name = bind_back; + values = { +v = 202306; +cxxmin = 26; + }; values = { v = 202202; cxxmin = 23; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 8e0ae682251..9721d1d23fe 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -511,7 +511,12 @@ #undef __glibcxx_want_make_from_tuple #if !defined(__cpp_lib_not_fn) -# if (__cplusplus >= 201703L) +# if (__cplusplus > 202302L) +# define __glibcxx_not_fn 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) +# define __cpp_lib_not_fn 202306L +# endif +# elif (__cplusplus >= 201703L) # define __glibcxx_not_fn 201603L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_not_fn) # define __cpp_lib_not_fn 201603L @@ -866,7 +871,12 @@ #undef __glibcxx_want_atomic_value_initialization #if !defined(__cpp_lib_bind_front) -# if (__cplusplus >= 202002L) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_front 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) +# define __cpp_lib_bind_front 202306L +# endif +# elif (__cplusplus >= 202002L) # define __glibcxx_bind_front 201907L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_front) # define __cpp_lib_bind_front 201907L @@ -876,7 +886,12 @@ #undef __glibcxx_want_bind_front #if !defined(__cpp_lib_bind_back) -# if (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) +# if (__cplusplus > 202302L) +# define __glibcxx_bind_back 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_bind_back) +# define __cpp_lib_bind_back 202306L +# endif +# elif (__cplusplus >= 202100L) && (__cpp_explicit_this_parameter) # define __glibcxx_bind_back 202202L # if