[libcxx-commits] [libcxx] [libc++][streams] P2495R3: Interfacing `stringstreams` with `string_view` (PR #80552)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Feb 3 08:48:28 PST 2024
https://github.com/H-G-Hristov created https://github.com/llvm/llvm-project/pull/80552
Implements P2495R3 <https://wg21.link/P2495R3>
- https://eel.is/c++draft/version.syn#headerref:%3csstream%3e
- https://eel.is/c++draft/stringbuf
- https://eel.is/c++draft/stringbuf.general
- https://eel.is/c++draft/stringbuf.cons
- https://eel.is/c++draft/stringbuf.members
- https://eel.is/c++draft/istringstream
- https://eel.is/c++draft/istringstream.general
- https://eel.is/c++draft/istringstream.cons
- https://eel.is/c++draft/istringstream.members
- https://eel.is/c++draft/ostringstream
- https://eel.is/c++draft/ostringstream.general
- https://eel.is/c++draft/ostringstream.cons
- https://eel.is/c++draft/ostringstream.members
- https://eel.is/c++draft/stringstream
- https://eel.is/c++draft/stringstream.general
- https://eel.is/c++draft/stringstream.cons
- https://eel.is/c++draft/stringstream.members
References:
- https://eel.is/c++draft/string.streams
>From 331e3a0ebf9fb552451530166134b1395a5e9ac0 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 31 Jan 2024 12:26:19 +0200
Subject: [PATCH 1/5] [libc++][streams] P2495R3: Interfacing `stringstreams`
with `string_view`
Implements P2495R3 <https://wg21.link/P2495R3>
- https://eel.is/c++draft/version.syn#headerref:%3csstream%3e
- https://eel.is/c++draft/stringbuf
- https://eel.is/c++draft/stringbuf.general
- https://eel.is/c++draft/stringbuf.cons
- https://eel.is/c++draft/stringbuf.members
- https://eel.is/c++draft/istringstream
- https://eel.is/c++draft/istringstream.general
- https://eel.is/c++draft/istringstream.cons
- https://eel.is/c++draft/istringstream.members
- https://eel.is/c++draft/ostringstream
- https://eel.is/c++draft/ostringstream.general
- https://eel.is/c++draft/ostringstream.cons
- https://eel.is/c++draft/ostringstream.members
- https://eel.is/c++draft/stringstream
- https://eel.is/c++draft/stringstream.general
- https://eel.is/c++draft/stringstream.cons
- https://eel.is/c++draft/stringstream.members
References:
- https://eel.is/c++draft/string.streams
---
libcxx/docs/ReleaseNotes/19.rst | 1 +
libcxx/docs/Status/Cxx2cPapers.csv | 2 +-
libcxx/include/sstream | 152 ++++++++++++++++++
.../string_view.mode.alloc.pass.cpp | 77 +++++++++
.../str.string_view.pass.cpp | 105 ++++++++++++
.../str.string_view.pass.cpp | 105 ++++++++++++
.../str.string_view.pass.cpp | 105 ++++++++++++
.../str.string_view.pass.cpp | 105 ++++++++++++
.../generate_feature_test_macro_components.py | 1 -
9 files changed, 651 insertions(+), 2 deletions(-)
create mode 100644 libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index db731de2e4399..f2ca6d073d2f1 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -40,6 +40,7 @@ Implemented Papers
- P2637R3 - Member ``visit``
- P2652R2 - Disallow User Specialization of ``allocator_traits``
+- P2495R3 - Interfacing ``stringstream``s with ``string_view``
Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index a62faee4f44e2..dfc4208b5ccb5 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -6,7 +6,7 @@
"`P2545R4 <https://wg21.link/P2545R4>`__","LWG","Read-Copy Update (RCU)","Varna June 2023","","",""
"`P2530R3 <https://wg21.link/P2530R3>`__","LWG","Hazard Pointers for C++26","Varna June 2023","","",""
"`P2538R1 <https://wg21.link/P2538R1>`__","LWG","ADL-proof ``std::projected``","Varna June 2023","|Complete|","18.0","|ranges|"
-"`P2495R3 <https://wg21.link/P2495R3>`__","LWG","Interfacing ``stringstreams`` with ``string_view``","Varna June 2023","","",""
+"`P2495R3 <https://wg21.link/P2495R3>`__","LWG","Interfacing ``stringstream``s with ``string_view``","Varna June 2023","|Complete|","19.0",""
"`P2510R3 <https://wg21.link/P2510R3>`__","LWG","Formatting pointers","Varna June 2023","|Complete| [#note-P2510R3]_","17.0","|format|"
"`P2198R7 <https://wg21.link/P2198R7>`__","LWG","Freestanding Feature-Test Macros and Implementation-Defined Extensions","Varna June 2023","","",""
"`P2338R4 <https://wg21.link/P2338R4>`__","LWG","Freestanding Library: Character primitives and the C library","Varna June 2023","","",""
diff --git a/libcxx/include/sstream b/libcxx/include/sstream
index 6c354cf0b3973..6f6da1cb9ba07 100644
--- a/libcxx/include/sstream
+++ b/libcxx/include/sstream
@@ -48,6 +48,13 @@ public:
template <class SAlloc>
explicit basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s,
ios_base::openmode which = ios_base::in | ios_base::out); // C++20
+ template<class T>
+ explicit basic_stringbuf(const T& t,
+ ios_base::openmode which = ios_base::in | ios_base::out); // Since C++26
+ template<class T>
+ basic_stringbuf(const T& t, const Allocator& a); // Since C++26
+ template<class T>
+ basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26
basic_stringbuf(basic_stringbuf&& rhs);
basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20
@@ -67,6 +74,8 @@ public:
template <class SAlloc>
void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20
void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20
+ template<class T>
+ void str(const T& t); // Since C++26
protected:
// [stringbuf.virtuals] Overridden virtual functions:
@@ -119,6 +128,12 @@ public:
template <class SAlloc>
explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s,
ios_base::openmode which = ios_base::in); // C++20
+ template<class T>
+ explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); // Since C++26
+ template<class T>
+ basic_istringstream(const T& t, const Allocator& a); // Since C++26
+ template<class T>
+ basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26
basic_istringstream(basic_istringstream&& rhs);
// [istringstream.assign] Assign and swap:
@@ -137,6 +152,8 @@ public:
template <class SAlloc>
void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20
void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20
+ template<class T>
+ void str(const T& t); // Since C++26
};
template <class charT, class traits, class Allocator>
@@ -178,6 +195,12 @@ public:
template <class SAlloc>
explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s,
ios_base::openmode which = ios_base::out); // C++20
+ template<class T>
+ explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out); // Since C++26
+ template<class T>
+ basic_ostringstream(const T& t, const Allocator& a); // Since C++26
+ template<class T>
+ basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26
basic_ostringstream(basic_ostringstream&& rhs);
// [ostringstream.assign] Assign and swap:
@@ -196,6 +219,8 @@ public:
template <class SAlloc>
void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20
void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20
+ template<class T>
+ void str(const T& t); // Since C++26
};
template <class charT, class traits, class Allocator>
@@ -237,6 +262,13 @@ public:
template <class SAlloc>
explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s,
ios_base::openmode which = ios_base::out | ios_base::in); // C++20
+ template<class T>
+ explicit basic_stringstream(const T& t,
+ ios_base::openmode which = ios_base::out | ios_base::in); // Since C++26
+ template<class T>
+ basic_stringstream(const T& t, const Allocator& a); // Since C++26
+ template<class T>
+ basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26
basic_stringstream(basic_stringstream&& rhs);
// [stringstream.assign] Assign and swap:
@@ -255,6 +287,8 @@ public:
template <class SAlloc>
void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20
void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20
+ template<class T>
+ void str(const T& t); // Since C++26
};
template <class charT, class traits, class Allocator>
@@ -274,10 +308,12 @@ typedef basic_stringstream<wchar_t> wstringstream;
#include <__availability>
#include <__config>
#include <__fwd/sstream.h>
+#include <__type_traits/is_convertible.h>
#include <__utility/swap.h>
#include <istream>
#include <ostream>
#include <string>
+#include <string_view>
#include <version>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -364,6 +400,30 @@ public:
}
#endif // _LIBCPP_STD_VER >= 20
+#if _LIBCPP_STD_VER >= 26
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const _Tp& __t,
+ ios_base::openmode __which = ios_base::in | ios_base::out)
+ : basic_stringbuf(__t, __which, _Allocator()) {}
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, const _Allocator& __a)
+ : basic_stringbuf(__t, ios_base::in | ios_base::out, __a) {}
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
+ : basic_stringbuf(__which, __a) {
+ basic_string_view<_CharT, _Traits> __sv = __t;
+ __str_ = __sv;
+ __init_buf_ptrs();
+ }
+
+#endif // _LIBCPP_STD_VER >= 26
+
basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); }
#if _LIBCPP_STD_VER >= 20
@@ -435,6 +495,18 @@ public:
}
#endif // _LIBCPP_STD_VER >= 20
+#if _LIBCPP_STD_VER >= 26
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
+ basic_string_view<_CharT, _Traits> __sv = __t;
+ __str_ = __sv;
+ __init_buf_ptrs();
+ }
+
+#endif // _LIBCPP_STD_VER >= 26
+
protected:
// [stringbuf.virtuals] Overridden virtual functions:
int_type underflow() override;
@@ -822,6 +894,24 @@ public:
: basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
#endif // _LIBCPP_STD_VER >= 20
+#if _LIBCPP_STD_VER >= 26
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in)
+ : basic_istringstream(__t, __which, _Allocator()) {}
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ basic_istringstream(const _Tp& __t, const _Allocator& __a) : basic_istringstream(__t, ios_base::in, __a) {}
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
+ : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {}
+
+#endif // _LIBCPP_STD_VER >= 26
+
_LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs)
: basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
@@ -871,6 +961,14 @@ public:
_LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
#endif // _LIBCPP_STD_VER >= 20
+
+#if _LIBCPP_STD_VER >= 26
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
+ rdbuf()->str(__t);
+ }
+#endif // _LIBCPP_STD_VER >= 26
};
template <class _CharT, class _Traits, class _Allocator>
@@ -929,6 +1027,24 @@ public:
: basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
#endif // _LIBCPP_STD_VER >= 20
+#if _LIBCPP_STD_VER >= 26
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out)
+ : basic_ostringstream(__t, __which, _Allocator()) {}
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ basic_ostringstream(const _Tp& __t, const _Allocator& __a) : basic_ostringstream(__t, ios_base::out, __a) {}
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
+ : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {}
+
+#endif // _LIBCPP_STD_VER >= 26
+
_LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs)
: basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_);
@@ -979,6 +1095,14 @@ public:
_LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
#endif // _LIBCPP_STD_VER >= 20
+
+#if _LIBCPP_STD_VER >= 26
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
+ rdbuf()->str(__t);
+ }
+#endif // _LIBCPP_STD_VER >= 26
};
template <class _CharT, class _Traits, class _Allocator>
@@ -1040,6 +1164,26 @@ public:
: basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
#endif // _LIBCPP_STD_VER >= 20
+#if _LIBCPP_STD_VER >= 26
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ explicit basic_stringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out | ios_base::in)
+ : basic_stringstream(__t, __which, _Allocator()) {}
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ basic_stringstream(const _Tp& __t, const _Allocator& __a)
+ : basic_stringstream(__t, ios_base::out | ios_base::in, __a) {}
+
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
+ : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)),
+ __sb_(__t, __which | ios_base::out | ios_base::in, __a) {}
+
+#endif // _LIBCPP_STD_VER >= 26
+
_LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs)
: basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
@@ -1089,6 +1233,14 @@ public:
_LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
#endif // _LIBCPP_STD_VER >= 20
+
+#if _LIBCPP_STD_VER >= 26
+ template <class _Tp>
+ requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
+ _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
+ rdbuf()->str(__t);
+ }
+#endif // _LIBCPP_STD_VER >= 26
};
template <class _CharT, class _Traits, class _Allocator>
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
new file mode 100644
index 0000000000000..659c89d2de5fb
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a);
+
+#include <array>
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <string_view>
+#include <type_traits>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_macros.h"
+
+using namespace std::string_literals;
+using namespace std::string_view_literals;
+
+#define STR(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ // const ChartT*
+ {
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(STR("zmt"));
+ assert(ss.view() == SV("zmt"));
+ }
+ {
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ STR("zmt"), std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+ // basic_string_view<CharT>
+ {
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(SV("zmt"));
+ assert(ss.view() == SV("zmt"));
+ }
+ {
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ SV("zmt"), std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+ // basic_string<CharT>
+ {
+ const std::basic_string<CharT> s(STR("zmt"));
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s);
+ assert(ss.view() == SV("zmt"));
+ }
+ {
+ const std::basic_string<CharT> s(STR("zmt"));
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s, std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
\ No newline at end of file
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
new file mode 100644
index 0000000000000..1a1b63171d6c2
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
@@ -0,0 +1,105 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_istringstream
+
+// template<class T>
+// void str(const T& t);
+
+#include <array>
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <string_view>
+#include <type_traits>
+
+#include "test_macros.h"
+
+using namespace std::string_literals;
+using namespace std::string_view_literals;
+
+template <typename S, typename T>
+concept HasStr = requires(S s, const T sv) {
+ { s.str(sv) };
+};
+
+struct SomeObject {};
+
+// std::istringstream
+static_assert(HasStr<std::istringstream, std::string_view>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::istringstream, std::wstring_view>);
+#endif
+static_assert(HasStr<std::istringstream, const char*>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::istringstream, const wchar_t*>);
+#endif
+static_assert(HasStr<std::istringstream, std::string>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::istringstream, std::wstring>);
+#endif
+static_assert(!HasStr<std::istringstream, std::array<char, 0>>);
+static_assert(!HasStr<std::istringstream, char>);
+static_assert(!HasStr<std::istringstream, int>);
+static_assert(!HasStr<std::istringstream, SomeObject>);
+static_assert(!HasStr<std::istringstream, std::nullptr_t>);
+
+// std::wistringstream
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(HasStr<std::wistringstream, std::wstring_view>);
+static_assert(!HasStr<std::wistringstream, std::string_view>);
+static_assert(HasStr<std::wistringstream, const wchar_t*>);
+static_assert(!HasStr<std::wistringstream, const char*>);
+static_assert(HasStr<std::wistringstream, std::wstring>);
+static_assert(!HasStr<std::wistringstream, std::string>);
+static_assert(!HasStr<std::istringstream, std::array<wchar_t, 0>>);
+static_assert(!HasStr<std::wistringstream, wchar_t>);
+static_assert(!HasStr<std::wistringstream, int>);
+static_assert(!HasStr<std::wistringstream, SomeObject>);
+static_assert(!HasStr<std::wistringstream, std::nullptr_t>);
+#endif
+
+int main(int, char**) {
+ {
+ std::istringstream ss;
+ assert(ss.str().empty());
+ ss.str("ba");
+ assert(ss.str() == "ba");
+ ss.str("ma"sv);
+ assert(ss.str() == "ma");
+ ss.str("zmt"s);
+ assert(ss.str() == "zmt");
+ const std::string s;
+ ss.str(s);
+ assert(ss.str().empty());
+ }
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ {
+ std::wistringstream ss;
+ assert(ss.str().empty());
+ ss.str(L"ba");
+ assert(ss.str() == L"ba");
+ ss.str(L"ma"sv);
+ assert(ss.str() == L"ma");
+ ss.str(L"zmt"s);
+ assert(ss.str() == L"zmt");
+ const std::wstring s;
+ ss.str(s);
+ assert(ss.str().empty());
+ }
+#endif
+
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
new file mode 100644
index 0000000000000..35a2e9754cc59
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
@@ -0,0 +1,105 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_ostringstream
+
+// template<class T>
+// void str(const T& t);
+
+#include <array>
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <string_view>
+#include <type_traits>
+
+#include "test_macros.h"
+
+using namespace std::string_literals;
+using namespace std::string_view_literals;
+
+template <typename S, typename T>
+concept HasStr = requires(S s, const T sv) {
+ { s.str(sv) };
+};
+
+struct SomeObject {};
+
+// std::ostringstream
+static_assert(HasStr<std::ostringstream, std::string_view>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::ostringstream, std::wstring_view>);
+#endif
+static_assert(HasStr<std::ostringstream, const char*>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::ostringstream, const wchar_t*>);
+#endif
+static_assert(HasStr<std::ostringstream, std::string>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::ostringstream, std::wstring>);
+#endif
+static_assert(!HasStr<std::ostringstream, std::array<char, 0>>);
+static_assert(!HasStr<std::ostringstream, char>);
+static_assert(!HasStr<std::ostringstream, int>);
+static_assert(!HasStr<std::ostringstream, SomeObject>);
+static_assert(!HasStr<std::ostringstream, std::nullptr_t>);
+
+// std::wostringstream
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(HasStr<std::wostringstream, std::wstring_view>);
+static_assert(!HasStr<std::wostringstream, std::string_view>);
+static_assert(HasStr<std::wostringstream, const wchar_t*>);
+static_assert(!HasStr<std::wostringstream, const char*>);
+static_assert(HasStr<std::wostringstream, std::wstring>);
+static_assert(!HasStr<std::wostringstream, std::string>);
+static_assert(!HasStr<std::ostringstream, std::array<wchar_t, 0>>);
+static_assert(!HasStr<std::wostringstream, wchar_t>);
+static_assert(!HasStr<std::wostringstream, int>);
+static_assert(!HasStr<std::wostringstream, SomeObject>);
+static_assert(!HasStr<std::wostringstream, std::nullptr_t>);
+#endif
+
+int main(int, char**) {
+ {
+ std::ostringstream ss;
+ assert(ss.str().empty());
+ ss.str("ba");
+ assert(ss.str() == "ba");
+ ss.str("ma"sv);
+ assert(ss.str() == "ma");
+ ss.str("zmt"s);
+ assert(ss.str() == "zmt");
+ const std::string s;
+ ss.str(s);
+ assert(ss.str().empty());
+ }
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ {
+ std::wostringstream ss;
+ assert(ss.str().empty());
+ ss.str(L"ba");
+ assert(ss.str() == L"ba");
+ ss.str(L"ma"sv);
+ assert(ss.str() == L"ma");
+ ss.str(L"zmt"s);
+ assert(ss.str() == L"zmt");
+ const std::wstring s;
+ ss.str(s);
+ assert(ss.str().empty());
+ }
+#endif
+
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
new file mode 100644
index 0000000000000..e84fe8457bb85
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
@@ -0,0 +1,105 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringbuf
+
+// template<class T>
+// void str(const T& t);
+
+#include <array>
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <string_view>
+#include <type_traits>
+
+#include "test_macros.h"
+
+using namespace std::string_literals;
+using namespace std::string_view_literals;
+
+template <typename S, typename T>
+concept HasStr = requires(S s, const T sv) {
+ { s.str(sv) };
+};
+
+struct SomeObject {};
+
+// std::stringbuf
+static_assert(HasStr<std::stringbuf, std::string_view>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::stringbuf, std::wstring_view>);
+#endif
+static_assert(HasStr<std::stringbuf, const char*>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::stringbuf, const wchar_t*>);
+#endif
+static_assert(HasStr<std::stringbuf, std::string>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::stringbuf, std::wstring>);
+#endif
+static_assert(!HasStr<std::stringbuf, std::array<char, 0>>);
+static_assert(!HasStr<std::stringbuf, char>);
+static_assert(!HasStr<std::stringbuf, int>);
+static_assert(!HasStr<std::stringbuf, SomeObject>);
+static_assert(!HasStr<std::stringbuf, std::nullptr_t>);
+
+// std::wstringbuf
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(HasStr<std::wstringbuf, std::wstring_view>);
+static_assert(!HasStr<std::wstringbuf, std::string_view>);
+static_assert(HasStr<std::wstringbuf, const wchar_t*>);
+static_assert(!HasStr<std::wstringbuf, const char*>);
+static_assert(HasStr<std::wstringbuf, std::wstring>);
+static_assert(!HasStr<std::wstringbuf, std::string>);
+static_assert(!HasStr<std::stringbuf, std::array<wchar_t, 0>>);
+static_assert(!HasStr<std::wstringbuf, wchar_t>);
+static_assert(!HasStr<std::wstringbuf, int>);
+static_assert(!HasStr<std::wstringbuf, SomeObject>);
+static_assert(!HasStr<std::wstringbuf, std::nullptr_t>);
+#endif
+
+int main(int, char**) {
+ {
+ std::stringbuf ss;
+ assert(ss.str().empty());
+ ss.str("ba");
+ assert(ss.str() == "ba");
+ ss.str("ma"sv);
+ assert(ss.str() == "ma");
+ ss.str("zmt"s);
+ assert(ss.str() == "zmt");
+ const std::string s;
+ ss.str(s);
+ assert(ss.str().empty());
+ }
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ {
+ std::wstringbuf ss;
+ assert(ss.str().empty());
+ ss.str(L"ba");
+ assert(ss.str() == L"ba");
+ ss.str(L"ma"sv);
+ assert(ss.str() == L"ma");
+ ss.str(L"zmt"s);
+ assert(ss.str() == L"zmt");
+ const std::wstring s;
+ ss.str(s);
+ assert(ss.str().empty());
+ }
+#endif
+
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
new file mode 100644
index 0000000000000..63624929d0981
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
@@ -0,0 +1,105 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// void str(const T& t);
+
+#include <array>
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <string_view>
+#include <type_traits>
+
+#include "test_macros.h"
+
+using namespace std::string_literals;
+using namespace std::string_view_literals;
+
+template <typename S, typename T>
+concept HasStr = requires(S s, const T sv) {
+ { s.str(sv) };
+};
+
+struct SomeObject {};
+
+// std::stringstream
+static_assert(HasStr<std::stringstream, std::string_view>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::stringstream, std::wstring_view>);
+#endif
+static_assert(HasStr<std::stringstream, const char*>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::stringstream, const wchar_t*>);
+#endif
+static_assert(HasStr<std::stringstream, std::string>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!HasStr<std::stringstream, std::wstring>);
+#endif
+static_assert(!HasStr<std::stringstream, std::array<char, 0>>);
+static_assert(!HasStr<std::stringstream, char>);
+static_assert(!HasStr<std::stringstream, int>);
+static_assert(!HasStr<std::stringstream, SomeObject>);
+static_assert(!HasStr<std::stringstream, std::nullptr_t>);
+
+// std::wstringstream
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(HasStr<std::wstringstream, std::wstring_view>);
+static_assert(!HasStr<std::wstringstream, std::string_view>);
+static_assert(HasStr<std::wstringstream, const wchar_t*>);
+static_assert(!HasStr<std::wstringstream, const char*>);
+static_assert(HasStr<std::wstringstream, std::wstring>);
+static_assert(!HasStr<std::wstringstream, std::string>);
+static_assert(!HasStr<std::stringstream, std::array<wchar_t, 0>>);
+static_assert(!HasStr<std::wstringstream, wchar_t>);
+static_assert(!HasStr<std::wstringstream, int>);
+static_assert(!HasStr<std::wstringstream, SomeObject>);
+static_assert(!HasStr<std::wstringstream, std::nullptr_t>);
+#endif
+
+int main(int, char**) {
+ {
+ std::stringstream ss;
+ assert(ss.str().empty());
+ ss.str("ba");
+ assert(ss.str() == "ba");
+ ss.str("ma"sv);
+ assert(ss.str() == "ma");
+ ss.str("zmt"s);
+ assert(ss.str() == "zmt");
+ const std::string s;
+ ss.str(s);
+ assert(ss.str().empty());
+ }
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ {
+ std::wstringstream ss;
+ assert(ss.str().empty());
+ ss.str(L"ba");
+ assert(ss.str() == L"ba");
+ ss.str(L"ma"sv);
+ assert(ss.str() == L"ma");
+ ss.str(L"zmt"s);
+ assert(ss.str() == L"zmt");
+ const std::wstring s;
+ ss.str(s);
+ assert(ss.str().empty());
+ }
+#endif
+
+ return 0;
+}
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 6078e811c8e1e..dd08880c04591 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -1108,7 +1108,6 @@ def add_version_header(tc):
"c++26": 202306 # P2495R3 Interfacing stringstreams with string_view
},
"headers": ["sstream"],
- "unimplemented": True,
},
{
"name": "__cpp_lib_stacktrace",
>From 7939810417a4519632340c3dec8a0509f700d152 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sat, 3 Feb 2024 08:46:30 +0200
Subject: [PATCH 2/5] Refactored: `str`, ctrs
---
.../string_view.alloc.pass.cpp | 106 +++++++++++
.../string_view.mode.alloc.pass.cpp | 169 +++++++++++++++---
.../string_view.mode.pass.cpp | 102 +++++++++++
.../str.string_view.pass.cpp | 99 ++++------
.../string_view.mode.alloc.pass.cpp | 132 ++++++++++++++
.../str.string_view.pass.cpp | 99 ++++------
.../str.string_view.pass.cpp | 100 ++++-------
.../str.string_view.pass.cpp | 99 ++++------
8 files changed, 617 insertions(+), 289 deletions(-)
create mode 100644 libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.alloc.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.alloc.pass.cpp
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.alloc.pass.cpp
new file mode 100644
index 0000000000000..2eb19ab608981
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.alloc.pass.cpp
@@ -0,0 +1,106 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_istringstream(const T& t, const Allocator& a);
+
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+struct SomeObject {};
+struct NonAllocator {};
+
+template <typename CharT>
+void test_constraints() {
+ // `const CharT*`
+ static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ test_allocator<CharT>>());
+ // `std::basic_string_view<CharT>`
+ static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ test_allocator<CharT>>());
+ // `std::basic_string<CharT>`
+ static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ test_allocator<CharT>>());
+
+ // Non-convertible to std::`basic_string_view<CharT>`
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ int,
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int&,
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ SomeObject,
+
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject&,
+ test_allocator<CharT>>());
+
+ // Allocator
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ NonAllocator>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const test_allocator<CharT> ca;
+
+ // const CharT*
+ {
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+}
+
+int main(int, char**) {
+ test_constraints<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_constraints<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
index 659c89d2de5fb..fc42fc5a8a413 100644
--- a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
@@ -21,57 +21,170 @@
#include <sstream>
#include <string>
#include <string_view>
-#include <type_traits>
#include "make_string.h"
#include "test_allocator.h"
+#include "test_convertible.h"
#include "test_macros.h"
-using namespace std::string_literals;
-using namespace std::string_view_literals;
+template <typename S, typename T, typename A>
+concept HasMember = requires(const T& sv, std::ios_base::openmode w, const A& a) {
+ { S(sv, w, a) };
+};
-#define STR(S) MAKE_STRING(CharT, S)
+template <typename CharT>
+void test_constraints() {
+ struct SomeObject {};
+ struct NonAllocator {};
+
+ // `const CharT*`
+ static_assert(HasMember<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ // `std::basic_string_view<CharT>`
+ static_assert(HasMember<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ // `std::basic_string<CharT>`
+ static_assert(HasMember<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+
+ // Non-convertible to std::`basic_string_view<CharT>`
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ int,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int&,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ SomeObject,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject&,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+
+ // Mode
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ SomeObject,
+ NonAllocator>());
+
+ // Allocator
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ std::ios_base::openmode,
+ NonAllocator>());
+}
+
+// #include <concepts>
+// #include <type_traits>
+
+// static_assert(std::is_constructible_v<std::istringstream, std::string_view>);
+// static_assert(test_convertible<std::basic_istringstream<char, std::char_traits<char>>,
+// const char*,
+// std::ios_base::openmode>());
+// static_assert(std::is_constructible_v<std::istringstream, int, test_allocator<int>>);
+
+// static_assert(HasMember<std::istringstream, std::string_view, test_allocator<char>>);
+
+// std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>
+// static_assert(HasMember<std::basic_istringstream<char, std::char_traits<char>, test_allocator<char>>,
+// const char*,
+// test_allocator<char>>);
+
+// // std::istringstream
+// static_assert(HasMember<std::istringstream, std::string_view>);
+// # ifndef TEST_HAS_NO_WIDE_CHARACTERS
+// static_assert(!HasMember<std::istringstream, std::wstring_view>);
+// # endif
+// static_assert(HasMember<std::istringstream, const char*>);
+// # ifndef TEST_HAS_NO_WIDE_CHARACTERS
+// static_assert(!HasMember<std::istringstream, const wchar_t*>);
+// # endif
+// static_assert(HasMember<std::istringstream, std::string>);
+// # ifndef TEST_HAS_NO_WIDE_CHARACTERS
+// static_assert(!HasMember<std::istringstream, std::wstring>);
+// # endif
+// static_assert(!HasMember<std::istringstream, std::array<char, 1>>);
+// static_assert(!HasMember<std::istringstream, std::array<char, 0>>);
+// // static_assert(!HasMember<std::istringstream, char>);
+// // static_assert(!HasMember<std::istringstream, int>);
+// static_assert(!HasMember<std::istringstream, SomeObject>);
+// static_assert(!HasMember<std::istringstream, std::nullptr_t>);
+
+// // std::wistringstream
+
+// # ifndef TEST_HAS_NO_WIDE_CHARACTERS
+// static_assert(HasMember<std::wistringstream, std::wstring_view>);
+// static_assert(!HasMember<std::wistringstream, std::string_view>);
+// static_assert(HasMember<std::wistringstream, const wchar_t*>);
+// static_assert(!HasMember<std::wistringstream, const char*>);
+// static_assert(HasMember<std::wistringstream, std::wstring>);
+// static_assert(!HasMember<std::wistringstream, std::string>);
+// static_assert(!HasMember<std::istringstream, std::array<wchar_t, 0>>);
+// // static_assert(!HasMember<std::wistringstream, wchar_t>);
+// // static_assert(!HasMember<std::wistringstream, int>);
+// static_assert(!HasMember<std::wistringstream, SomeObject>);
+// static_assert(!HasMember<std::wistringstream, std::nullptr_t>);
+// # endif
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
#define SV(S) MAKE_STRING_VIEW(CharT, S)
template <class CharT>
static void test() {
- // const ChartT*
- {
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(STR("zmt"));
- assert(ss.view() == SV("zmt"));
- }
+ const test_allocator<CharT> ca;
+
+ // const CharT*
{
const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- STR("zmt"), std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
- }
- // basic_string_view<CharT>
- {
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(SV("zmt"));
- assert(ss.view() == SV("zmt"));
+ CS("zmt"), std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
}
+ // std::basic_string_view<CharT>
{
+ const auto csv = SV("zmt");
const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- SV("zmt"), std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
- }
- // basic_string<CharT>
- {
- const std::basic_string<CharT> s(STR("zmt"));
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s);
- assert(ss.view() == SV("zmt"));
+ csv, std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
}
+ // std::basic_string<CharT>
{
- const std::basic_string<CharT> s(STR("zmt"));
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s, std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
+ const auto cs = ST("zmt");
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ cs, std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
}
}
int main(int, char**) {
+ test_constraints<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_constraints<wchar_t>();
test<wchar_t>();
#endif
return 0;
-}
\ No newline at end of file
+}
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.pass.cpp
new file mode 100644
index 0000000000000..86f41cc3b62db
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.pass.cpp
@@ -0,0 +1,102 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_istringstream(const T& t, ios_base::openmode which);
+
+#include <array>
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+struct SomeObject {};
+
+template <typename CharT>
+void test_constraints() {
+ // `const CharT*`
+ // static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>>,
+ // const CharT*,
+ // std::ios_base::openmode>());
+ // `std::basic_string_view<CharT>`
+ // static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>>,
+ // std::basic_string_view<CharT, std::char_traits<CharT>>,
+ // std::ios_base::openmode>());
+ // // `std::basic_string<CharT>`
+ // static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ // std::basic_string<CharT>,
+ // std::ios_base::openmode>());
+
+ // // Non-convertible to std::`basic_string_view<CharT>`
+ // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ // int,
+ // std::ios_base::openmode>());
+ // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ // const int&,
+ // std::ios_base::openmode>());
+ // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ // SomeObject,
+ // std::ios_base::openmode>());
+ // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ // const SomeObject&,
+ // std::ios_base::openmode>());
+
+ // // Mode
+ // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ // std::basic_string<CharT>,
+ // SomeObject>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ // const CharT*
+ {
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ CS("zmt"), std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ csv, std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+}
+
+int main(int, char**) {
+ test_constraints<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_constraints<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
index 1a1b63171d6c2..501f76d00acfe 100644
--- a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
@@ -16,89 +16,58 @@
// template<class T>
// void str(const T& t);
-#include <array>
#include <cassert>
#include <sstream>
#include <string>
#include <string_view>
-#include <type_traits>
+#include "make_string.h"
#include "test_macros.h"
-using namespace std::string_literals;
-using namespace std::string_view_literals;
-
template <typename S, typename T>
-concept HasStr = requires(S s, const T sv) {
+concept HasMember = requires(S s, const T& sv) {
{ s.str(sv) };
};
struct SomeObject {};
-// std::istringstream
-static_assert(HasStr<std::istringstream, std::string_view>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::istringstream, std::wstring_view>);
-#endif
-static_assert(HasStr<std::istringstream, const char*>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::istringstream, const wchar_t*>);
-#endif
-static_assert(HasStr<std::istringstream, std::string>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::istringstream, std::wstring>);
-#endif
-static_assert(!HasStr<std::istringstream, std::array<char, 0>>);
-static_assert(!HasStr<std::istringstream, char>);
-static_assert(!HasStr<std::istringstream, int>);
-static_assert(!HasStr<std::istringstream, SomeObject>);
-static_assert(!HasStr<std::istringstream, std::nullptr_t>);
+template <typename CharT>
+void test_constraints() {
+ static_assert(HasMember<std::basic_istringstream<CharT>, const CharT*>);
+ static_assert(HasMember<std::basic_istringstream<CharT>, std::basic_string_view<CharT>>);
+ static_assert(HasMember<std::basic_istringstream<CharT>, std::basic_string<CharT>>);
-// std::wistringstream
+ static_assert(!HasMember<std::basic_istringstream<CharT>, char>);
+ static_assert(!HasMember<std::basic_istringstream<CharT>, int>);
+ static_assert(!HasMember<std::basic_istringstream<CharT>, SomeObject>);
+ static_assert(!HasMember<std::basic_istringstream<CharT>, std::nullptr_t>);
+}
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(HasStr<std::wistringstream, std::wstring_view>);
-static_assert(!HasStr<std::wistringstream, std::string_view>);
-static_assert(HasStr<std::wistringstream, const wchar_t*>);
-static_assert(!HasStr<std::wistringstream, const char*>);
-static_assert(HasStr<std::wistringstream, std::wstring>);
-static_assert(!HasStr<std::wistringstream, std::string>);
-static_assert(!HasStr<std::istringstream, std::array<wchar_t, 0>>);
-static_assert(!HasStr<std::wistringstream, wchar_t>);
-static_assert(!HasStr<std::wistringstream, int>);
-static_assert(!HasStr<std::wistringstream, SomeObject>);
-static_assert(!HasStr<std::wistringstream, std::nullptr_t>);
-#endif
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
-int main(int, char**) {
- {
- std::istringstream ss;
- assert(ss.str().empty());
- ss.str("ba");
- assert(ss.str() == "ba");
- ss.str("ma"sv);
- assert(ss.str() == "ma");
- ss.str("zmt"s);
- assert(ss.str() == "zmt");
- const std::string s;
- ss.str(s);
- assert(ss.str().empty());
- }
+template <typename CharT>
+void test() {
+ std::basic_istringstream<CharT> ss;
+ assert(ss.str().empty());
+ ss.str(CS("ba"));
+ assert(ss.str() == CS("ba"));
+ ss.str(SV("ma"));
+ assert(ss.str() == CS("ma"));
+ ss.str(ST("zmt"));
+ assert(ss.str() == CS("zmt"));
+ const std::basic_string<CharT> s;
+ ss.str(s);
+ assert(ss.str().empty());
+}
+int main(int, char**) {
+ test_constraints<char>();
+ test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- {
- std::wistringstream ss;
- assert(ss.str().empty());
- ss.str(L"ba");
- assert(ss.str() == L"ba");
- ss.str(L"ma"sv);
- assert(ss.str() == L"ma");
- ss.str(L"zmt"s);
- assert(ss.str() == L"zmt");
- const std::wstring s;
- ss.str(s);
- assert(ss.str().empty());
- }
+ test_constraints<wchar_t>();
+ test<wchar_t>();
#endif
return 0;
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.alloc.pass.cpp
new file mode 100644
index 0000000000000..59659505055f5
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.alloc.pass.cpp
@@ -0,0 +1,132 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a);
+
+#include <array>
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+struct SomeObject {};
+struct NonAllocator {};
+
+template <typename CharT>
+void test_constraints() {
+ // `const CharT*`
+ static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ // `std::basic_string_view<CharT>`
+ static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ // `std::basic_string<CharT>`
+ static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+
+ // Non-convertible to std::`basic_string_view<CharT>`
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ int,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int&,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ SomeObject,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject&,
+ std::ios_base::openmode,
+ test_allocator<CharT>>());
+
+ // Mode
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ SomeObject,
+ NonAllocator>());
+
+ // Allocator
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string<CharT>,
+ std::ios_base::openmode,
+ NonAllocator>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ using namespace std::string_literals;
+ using namespace std::string_view_literals;
+
+ // const CharT*
+ {
+ const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"));
+ assert(ss.view() == SV("zmt"));
+ }
+ {
+ const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ CS("zmt"), std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+ // std::basic_string_view<CharT>
+ {
+ const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(SV("zmt"));
+ assert(ss.view() == SV("zmt"));
+ }
+ {
+ const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ SV("zmt"), std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+ // std::basic_string<CharT>
+ {
+ const std::basic_string<CharT> s(ST("zmt"));
+ const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s);
+ assert(ss.view() == SV("zmt"));
+ }
+ {
+ const std::basic_string<CharT> s(ST("zmt"));
+ const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s, std::ios_base::binary);
+ assert(ss.view() == SV("zmt"));
+ }
+}
+
+int main(int, char**) {
+ test_constraints<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_constraints<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
index 35a2e9754cc59..018be464f61d3 100644
--- a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
@@ -16,89 +16,58 @@
// template<class T>
// void str(const T& t);
-#include <array>
#include <cassert>
#include <sstream>
#include <string>
#include <string_view>
-#include <type_traits>
+#include "make_string.h"
#include "test_macros.h"
-using namespace std::string_literals;
-using namespace std::string_view_literals;
-
template <typename S, typename T>
-concept HasStr = requires(S s, const T sv) {
+concept HasMember = requires(S s, const T& sv) {
{ s.str(sv) };
};
struct SomeObject {};
-// std::ostringstream
-static_assert(HasStr<std::ostringstream, std::string_view>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::ostringstream, std::wstring_view>);
-#endif
-static_assert(HasStr<std::ostringstream, const char*>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::ostringstream, const wchar_t*>);
-#endif
-static_assert(HasStr<std::ostringstream, std::string>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::ostringstream, std::wstring>);
-#endif
-static_assert(!HasStr<std::ostringstream, std::array<char, 0>>);
-static_assert(!HasStr<std::ostringstream, char>);
-static_assert(!HasStr<std::ostringstream, int>);
-static_assert(!HasStr<std::ostringstream, SomeObject>);
-static_assert(!HasStr<std::ostringstream, std::nullptr_t>);
+template <typename CharT>
+void test_constraints() {
+ static_assert(HasMember<std::basic_ostringstream<CharT>, const CharT*>);
+ static_assert(HasMember<std::basic_ostringstream<CharT>, std::basic_string_view<CharT>>);
+ static_assert(HasMember<std::basic_ostringstream<CharT>, std::basic_string<CharT>>);
-// std::wostringstream
+ static_assert(!HasMember<std::basic_ostringstream<CharT>, char>);
+ static_assert(!HasMember<std::basic_ostringstream<CharT>, int>);
+ static_assert(!HasMember<std::basic_ostringstream<CharT>, SomeObject>);
+ static_assert(!HasMember<std::basic_ostringstream<CharT>, std::nullptr_t>);
+}
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(HasStr<std::wostringstream, std::wstring_view>);
-static_assert(!HasStr<std::wostringstream, std::string_view>);
-static_assert(HasStr<std::wostringstream, const wchar_t*>);
-static_assert(!HasStr<std::wostringstream, const char*>);
-static_assert(HasStr<std::wostringstream, std::wstring>);
-static_assert(!HasStr<std::wostringstream, std::string>);
-static_assert(!HasStr<std::ostringstream, std::array<wchar_t, 0>>);
-static_assert(!HasStr<std::wostringstream, wchar_t>);
-static_assert(!HasStr<std::wostringstream, int>);
-static_assert(!HasStr<std::wostringstream, SomeObject>);
-static_assert(!HasStr<std::wostringstream, std::nullptr_t>);
-#endif
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
-int main(int, char**) {
- {
- std::ostringstream ss;
- assert(ss.str().empty());
- ss.str("ba");
- assert(ss.str() == "ba");
- ss.str("ma"sv);
- assert(ss.str() == "ma");
- ss.str("zmt"s);
- assert(ss.str() == "zmt");
- const std::string s;
- ss.str(s);
- assert(ss.str().empty());
- }
+template <typename CharT>
+void test() {
+ std::basic_ostringstream<CharT> ss;
+ assert(ss.str().empty());
+ ss.str(CS("ba"));
+ assert(ss.str() == CS("ba"));
+ ss.str(SV("ma"));
+ assert(ss.str() == CS("ma"));
+ ss.str(ST("zmt"));
+ assert(ss.str() == CS("zmt"));
+ const std::basic_string<CharT> s;
+ ss.str(s);
+ assert(ss.str().empty());
+}
+int main(int, char**) {
+ test_constraints<char>();
+ test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- {
- std::wostringstream ss;
- assert(ss.str().empty());
- ss.str(L"ba");
- assert(ss.str() == L"ba");
- ss.str(L"ma"sv);
- assert(ss.str() == L"ma");
- ss.str(L"zmt"s);
- assert(ss.str() == L"zmt");
- const std::wstring s;
- ss.str(s);
- assert(ss.str().empty());
- }
+ test_constraints<wchar_t>();
+ test<wchar_t>();
#endif
return 0;
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
index e84fe8457bb85..f0fbc7d273f95 100644
--- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
@@ -15,90 +15,58 @@
// template<class T>
// void str(const T& t);
-
-#include <array>
#include <cassert>
#include <sstream>
#include <string>
#include <string_view>
-#include <type_traits>
+#include "make_string.h"
#include "test_macros.h"
-using namespace std::string_literals;
-using namespace std::string_view_literals;
-
template <typename S, typename T>
-concept HasStr = requires(S s, const T sv) {
+concept HasMember = requires(S s, const T& sv) {
{ s.str(sv) };
};
struct SomeObject {};
-// std::stringbuf
-static_assert(HasStr<std::stringbuf, std::string_view>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::stringbuf, std::wstring_view>);
-#endif
-static_assert(HasStr<std::stringbuf, const char*>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::stringbuf, const wchar_t*>);
-#endif
-static_assert(HasStr<std::stringbuf, std::string>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::stringbuf, std::wstring>);
-#endif
-static_assert(!HasStr<std::stringbuf, std::array<char, 0>>);
-static_assert(!HasStr<std::stringbuf, char>);
-static_assert(!HasStr<std::stringbuf, int>);
-static_assert(!HasStr<std::stringbuf, SomeObject>);
-static_assert(!HasStr<std::stringbuf, std::nullptr_t>);
+template <typename CharT>
+void test_constraints() {
+ static_assert(HasMember<std::basic_stringbuf<CharT>, const CharT*>);
+ static_assert(HasMember<std::basic_stringbuf<CharT>, std::basic_string_view<CharT>>);
+ static_assert(HasMember<std::basic_stringbuf<CharT>, std::basic_string<CharT>>);
-// std::wstringbuf
+ static_assert(!HasMember<std::basic_stringbuf<CharT>, char>);
+ static_assert(!HasMember<std::basic_stringbuf<CharT>, int>);
+ static_assert(!HasMember<std::basic_stringbuf<CharT>, SomeObject>);
+ static_assert(!HasMember<std::basic_stringbuf<CharT>, std::nullptr_t>);
+}
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(HasStr<std::wstringbuf, std::wstring_view>);
-static_assert(!HasStr<std::wstringbuf, std::string_view>);
-static_assert(HasStr<std::wstringbuf, const wchar_t*>);
-static_assert(!HasStr<std::wstringbuf, const char*>);
-static_assert(HasStr<std::wstringbuf, std::wstring>);
-static_assert(!HasStr<std::wstringbuf, std::string>);
-static_assert(!HasStr<std::stringbuf, std::array<wchar_t, 0>>);
-static_assert(!HasStr<std::wstringbuf, wchar_t>);
-static_assert(!HasStr<std::wstringbuf, int>);
-static_assert(!HasStr<std::wstringbuf, SomeObject>);
-static_assert(!HasStr<std::wstringbuf, std::nullptr_t>);
-#endif
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
-int main(int, char**) {
- {
- std::stringbuf ss;
- assert(ss.str().empty());
- ss.str("ba");
- assert(ss.str() == "ba");
- ss.str("ma"sv);
- assert(ss.str() == "ma");
- ss.str("zmt"s);
- assert(ss.str() == "zmt");
- const std::string s;
- ss.str(s);
- assert(ss.str().empty());
- }
+template <typename CharT>
+void test() {
+ std::basic_stringbuf<CharT> ss;
+ assert(ss.str().empty());
+ ss.str(CS("ba"));
+ assert(ss.str() == CS("ba"));
+ ss.str(SV("ma"));
+ assert(ss.str() == CS("ma"));
+ ss.str(ST("zmt"));
+ assert(ss.str() == CS("zmt"));
+ const std::basic_string<CharT> s;
+ ss.str(s);
+ assert(ss.str().empty());
+}
+int main(int, char**) {
+ test_constraints<char>();
+ test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- {
- std::wstringbuf ss;
- assert(ss.str().empty());
- ss.str(L"ba");
- assert(ss.str() == L"ba");
- ss.str(L"ma"sv);
- assert(ss.str() == L"ma");
- ss.str(L"zmt"s);
- assert(ss.str() == L"zmt");
- const std::wstring s;
- ss.str(s);
- assert(ss.str().empty());
- }
+ test_constraints<wchar_t>();
+ test<wchar_t>();
#endif
return 0;
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
index 63624929d0981..76c2963580911 100644
--- a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
@@ -16,89 +16,58 @@
// template<class T>
// void str(const T& t);
-#include <array>
#include <cassert>
#include <sstream>
#include <string>
#include <string_view>
-#include <type_traits>
+#include "make_string.h"
#include "test_macros.h"
-using namespace std::string_literals;
-using namespace std::string_view_literals;
-
template <typename S, typename T>
-concept HasStr = requires(S s, const T sv) {
+concept HasMember = requires(S s, const T& sv) {
{ s.str(sv) };
};
struct SomeObject {};
-// std::stringstream
-static_assert(HasStr<std::stringstream, std::string_view>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::stringstream, std::wstring_view>);
-#endif
-static_assert(HasStr<std::stringstream, const char*>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::stringstream, const wchar_t*>);
-#endif
-static_assert(HasStr<std::stringstream, std::string>);
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!HasStr<std::stringstream, std::wstring>);
-#endif
-static_assert(!HasStr<std::stringstream, std::array<char, 0>>);
-static_assert(!HasStr<std::stringstream, char>);
-static_assert(!HasStr<std::stringstream, int>);
-static_assert(!HasStr<std::stringstream, SomeObject>);
-static_assert(!HasStr<std::stringstream, std::nullptr_t>);
+template <typename CharT>
+void test_constraints() {
+ static_assert(HasMember<std::basic_stringstream<CharT>, const CharT*>);
+ static_assert(HasMember<std::basic_stringstream<CharT>, std::basic_string_view<CharT>>);
+ static_assert(HasMember<std::basic_stringstream<CharT>, std::basic_string<CharT>>);
-// std::wstringstream
+ static_assert(!HasMember<std::basic_stringstream<CharT>, char>);
+ static_assert(!HasMember<std::basic_stringstream<CharT>, int>);
+ static_assert(!HasMember<std::basic_stringstream<CharT>, SomeObject>);
+ static_assert(!HasMember<std::basic_stringstream<CharT>, std::nullptr_t>);
+}
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(HasStr<std::wstringstream, std::wstring_view>);
-static_assert(!HasStr<std::wstringstream, std::string_view>);
-static_assert(HasStr<std::wstringstream, const wchar_t*>);
-static_assert(!HasStr<std::wstringstream, const char*>);
-static_assert(HasStr<std::wstringstream, std::wstring>);
-static_assert(!HasStr<std::wstringstream, std::string>);
-static_assert(!HasStr<std::stringstream, std::array<wchar_t, 0>>);
-static_assert(!HasStr<std::wstringstream, wchar_t>);
-static_assert(!HasStr<std::wstringstream, int>);
-static_assert(!HasStr<std::wstringstream, SomeObject>);
-static_assert(!HasStr<std::wstringstream, std::nullptr_t>);
-#endif
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
-int main(int, char**) {
- {
- std::stringstream ss;
- assert(ss.str().empty());
- ss.str("ba");
- assert(ss.str() == "ba");
- ss.str("ma"sv);
- assert(ss.str() == "ma");
- ss.str("zmt"s);
- assert(ss.str() == "zmt");
- const std::string s;
- ss.str(s);
- assert(ss.str().empty());
- }
+template <typename CharT>
+void test() {
+ std::basic_stringstream<CharT> ss;
+ assert(ss.str().empty());
+ ss.str(CS("ba"));
+ assert(ss.str() == CS("ba"));
+ ss.str(SV("ma"));
+ assert(ss.str() == CS("ma"));
+ ss.str(ST("zmt"));
+ assert(ss.str() == CS("zmt"));
+ const std::basic_string<CharT> s;
+ ss.str(s);
+ assert(ss.str().empty());
+}
+int main(int, char**) {
+ test_constraints<char>();
+ test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- {
- std::wstringstream ss;
- assert(ss.str().empty());
- ss.str(L"ba");
- assert(ss.str() == L"ba");
- ss.str(L"ma"sv);
- assert(ss.str() == L"ma");
- ss.str(L"zmt"s);
- assert(ss.str() == L"zmt");
- const std::wstring s;
- ss.str(s);
- assert(ss.str().empty());
- }
+ test_constraints<wchar_t>();
+ test<wchar_t>();
#endif
return 0;
>From 89601ebc492d1c54ef69fff2dd0da74d0860f016 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sat, 3 Feb 2024 12:31:16 +0200
Subject: [PATCH 3/5] Added all tests
---
.../string_view.alloc.pass.cpp | 62 +++----
.../string_view.mode.alloc.pass.cpp | 153 +++++++-----------
.../string_view.mode.pass.cpp | 94 ++++++-----
.../str.string_view.pass.cpp | 26 +--
.../string_view.alloc.pass.cpp | 114 +++++++++++++
.../string_view.mode.alloc.pass.cpp | 119 ++++++++------
.../string_view.mode.pass.cpp | 116 +++++++++++++
.../str.string_view.pass.cpp | 26 +--
.../stringbuf.cons/string_view.alloc.pass.cpp | 112 +++++++++++++
.../string_view.mode.alloc.pass.cpp | 141 ++++++++++++++++
.../stringbuf.cons/string_view.mode.pass.cpp | 111 +++++++++++++
.../str.string_view.pass.cpp | 26 +--
.../string_view.alloc.pass.cpp | 112 +++++++++++++
.../string_view.mode.alloc.pass.cpp | 141 ++++++++++++++++
.../string_view.mode.pass.cpp | 112 +++++++++++++
.../str.string_view.pass.cpp | 26 +--
16 files changed, 1220 insertions(+), 271 deletions(-)
create mode 100644 libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.alloc.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.alloc.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.alloc.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.alloc.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.alloc.pass.cpp
create mode 100644 libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.pass.cpp
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.alloc.pass.cpp
index 2eb19ab608981..92ec33f6a0d61 100644
--- a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.alloc.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.alloc.pass.cpp
@@ -17,6 +17,7 @@
// basic_istringstream(const T& t, const Allocator& a);
#include <cassert>
+#include <concepts>
#include <sstream>
#include <string>
#include <string_view>
@@ -26,43 +27,50 @@
#include "test_convertible.h"
#include "test_macros.h"
-struct SomeObject {};
-struct NonAllocator {};
-
template <typename CharT>
-void test_constraints() {
+void test_sfinae() {
+ struct SomeObject {};
+ struct NonAllocator {};
+
// `const CharT*`
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ const test_allocator<CharT>>);
static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
const CharT*,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
// `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const test_allocator<CharT>>);
static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
std::basic_string_view<CharT>,
test_allocator<CharT>>());
// `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ const test_allocator<CharT>>);
static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
- test_allocator<CharT>>());
-
- // Non-convertible to std::`basic_string_view<CharT>`
- static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- int,
- test_allocator<CharT>>());
- static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- const int&,
- test_allocator<CharT>>());
- static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- SomeObject,
+ const std::basic_string<CharT>,
+ const test_allocator<CharT>>());
- test_allocator<CharT>>());
+ // String-view-like
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ const test_allocator<CharT>>);
static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- const SomeObject&,
- test_allocator<CharT>>());
+ const SomeObject,
+ const test_allocator<CharT>>());
// Allocator
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const NonAllocator>);
static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
- NonAllocator>());
+ const std::basic_string_view<CharT>,
+ const NonAllocator>());
}
#define CS(S) MAKE_CSTRING(CharT, S)
@@ -75,31 +83,31 @@ static void test() {
// const CharT*
{
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), ca);
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
}
// std::basic_string_view<CharT>
{
const auto csv = SV("zmt");
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, ca);
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
}
// std::basic_string<CharT>
{
const auto cs = ST("zmt");
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, ca);
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
}
}
int main(int, char**) {
- test_constraints<char>();
+ test_sfinae<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test_constraints<wchar_t>();
+ test_sfinae<wchar_t>();
test<wchar_t>();
#endif
return 0;
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
index fc42fc5a8a413..a8c4b80cb032b 100644
--- a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.alloc.pass.cpp
@@ -16,8 +16,8 @@
// template<class T>
// basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a);
-#include <array>
#include <cassert>
+#include <concepts>
#include <sstream>
#include <string>
#include <string_view>
@@ -27,125 +27,82 @@
#include "test_convertible.h"
#include "test_macros.h"
-template <typename S, typename T, typename A>
-concept HasMember = requires(const T& sv, std::ios_base::openmode w, const A& a) {
- { S(sv, w, a) };
-};
-
template <typename CharT>
-void test_constraints() {
+void test_sfinae() {
struct SomeObject {};
struct NonAllocator {};
// `const CharT*`
- static_assert(HasMember<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- const CharT*,
- test_allocator<CharT>>);
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ test_allocator<CharT>>);
static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
const CharT*,
std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
// `std::basic_string_view<CharT>`
- static_assert(HasMember<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string_view<CharT>,
- test_allocator<CharT>>);
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>);
static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string_view<CharT>,
+ const std::basic_string_view<CharT>,
std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
// `std::basic_string<CharT>`
- static_assert(HasMember<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
- std::ios_base::openmode,
- test_allocator<CharT>>);
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
+ const std::basic_string<CharT>,
std::ios_base::openmode,
- test_allocator<CharT>>());
-
- // Non-convertible to std::`basic_string_view<CharT>`
+ const test_allocator<CharT>>());
+
+ // String-view-like
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- int,
+ const int,
std::ios_base::openmode,
- test_allocator<CharT>>());
- static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- const int&,
- std::ios_base::openmode,
- test_allocator<CharT>>());
- static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- SomeObject,
- std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
+
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- const SomeObject&,
+ const SomeObject,
std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
// Mode
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ SomeObject,
+ const NonAllocator>);
static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
+ const std::basic_string_view<CharT>,
SomeObject,
- NonAllocator>());
+ const NonAllocator>());
// Allocator
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ const NonAllocator>);
static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
+ const std::basic_string_view<CharT>,
std::ios_base::openmode,
- NonAllocator>());
+ const NonAllocator>());
}
-// #include <concepts>
-// #include <type_traits>
-
-// static_assert(std::is_constructible_v<std::istringstream, std::string_view>);
-// static_assert(test_convertible<std::basic_istringstream<char, std::char_traits<char>>,
-// const char*,
-// std::ios_base::openmode>());
-// static_assert(std::is_constructible_v<std::istringstream, int, test_allocator<int>>);
-
-// static_assert(HasMember<std::istringstream, std::string_view, test_allocator<char>>);
-
-// std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>
-// static_assert(HasMember<std::basic_istringstream<char, std::char_traits<char>, test_allocator<char>>,
-// const char*,
-// test_allocator<char>>);
-
-// // std::istringstream
-// static_assert(HasMember<std::istringstream, std::string_view>);
-// # ifndef TEST_HAS_NO_WIDE_CHARACTERS
-// static_assert(!HasMember<std::istringstream, std::wstring_view>);
-// # endif
-// static_assert(HasMember<std::istringstream, const char*>);
-// # ifndef TEST_HAS_NO_WIDE_CHARACTERS
-// static_assert(!HasMember<std::istringstream, const wchar_t*>);
-// # endif
-// static_assert(HasMember<std::istringstream, std::string>);
-// # ifndef TEST_HAS_NO_WIDE_CHARACTERS
-// static_assert(!HasMember<std::istringstream, std::wstring>);
-// # endif
-// static_assert(!HasMember<std::istringstream, std::array<char, 1>>);
-// static_assert(!HasMember<std::istringstream, std::array<char, 0>>);
-// // static_assert(!HasMember<std::istringstream, char>);
-// // static_assert(!HasMember<std::istringstream, int>);
-// static_assert(!HasMember<std::istringstream, SomeObject>);
-// static_assert(!HasMember<std::istringstream, std::nullptr_t>);
-
-// // std::wistringstream
-
-// # ifndef TEST_HAS_NO_WIDE_CHARACTERS
-// static_assert(HasMember<std::wistringstream, std::wstring_view>);
-// static_assert(!HasMember<std::wistringstream, std::string_view>);
-// static_assert(HasMember<std::wistringstream, const wchar_t*>);
-// static_assert(!HasMember<std::wistringstream, const char*>);
-// static_assert(HasMember<std::wistringstream, std::wstring>);
-// static_assert(!HasMember<std::wistringstream, std::string>);
-// static_assert(!HasMember<std::istringstream, std::array<wchar_t, 0>>);
-// // static_assert(!HasMember<std::wistringstream, wchar_t>);
-// // static_assert(!HasMember<std::wistringstream, int>);
-// static_assert(!HasMember<std::wistringstream, SomeObject>);
-// static_assert(!HasMember<std::wistringstream, std::nullptr_t>);
-// # endif
-
#define CS(S) MAKE_CSTRING(CharT, S)
#define ST(S) MAKE_STRING(CharT, S)
#define SV(S) MAKE_STRING_VIEW(CharT, S)
@@ -156,7 +113,7 @@ static void test() {
// const CharT*
{
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
CS("zmt"), std::ios_base::binary, ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
@@ -164,26 +121,24 @@ static void test() {
// std::basic_string_view<CharT>
{
const auto csv = SV("zmt");
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- csv, std::ios_base::binary, ca);
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary, ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
}
// std::basic_string<CharT>
{
const auto cs = ST("zmt");
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- cs, std::ios_base::binary, ca);
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary, ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
}
}
int main(int, char**) {
- test_constraints<char>();
+ test_sfinae<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test_constraints<wchar_t>();
+ test_sfinae<wchar_t>();
test<wchar_t>();
#endif
return 0;
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.pass.cpp
index 86f41cc3b62db..46e4d864cc122 100644
--- a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string_view.mode.pass.cpp
@@ -16,8 +16,8 @@
// template<class T>
// basic_istringstream(const T& t, ios_base::openmode which);
-#include <array>
#include <cassert>
+#include <concepts>
#include <sstream>
#include <string>
#include <string_view>
@@ -27,41 +27,56 @@
#include "test_convertible.h"
#include "test_macros.h"
-struct SomeObject {};
-
template <typename CharT>
-void test_constraints() {
+void test_sfinae() {
+ struct SomeObject {};
+
// `const CharT*`
- // static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>>,
- // const CharT*,
- // std::ios_base::openmode>());
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>>,
+ const CharT*,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>>,
+ const CharT*,
+ std::ios_base::openmode>());
// `std::basic_string_view<CharT>`
- // static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>>,
- // std::basic_string_view<CharT, std::char_traits<CharT>>,
- // std::ios_base::openmode>());
- // // `std::basic_string<CharT>`
- // static_assert(test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- // std::basic_string<CharT>,
- // std::ios_base::openmode>());
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>>,
+ const std::basic_string_view<CharT, std::char_traits<CharT>>,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>>,
+ const std::basic_string_view<CharT, std::char_traits<CharT>>,
+ std::ios_base::openmode>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode>());
- // // Non-convertible to std::`basic_string_view<CharT>`
- // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- // int,
- // std::ios_base::openmode>());
- // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- // const int&,
- // std::ios_base::openmode>());
- // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- // SomeObject,
- // std::ios_base::openmode>());
- // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- // const SomeObject&,
- // std::ios_base::openmode>());
+ // String-view-like
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode>());
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode>());
- // // Mode
- // static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- // std::basic_string<CharT>,
- // SomeObject>());
+ // Mode
+ static_assert(
+ !std::constructible_from<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const SomeObject>);
+ static_assert(!test_convertible<std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const SomeObject>());
}
#define CS(S) MAKE_CSTRING(CharT, S)
@@ -72,30 +87,29 @@ template <class CharT>
static void test() {
// const CharT*
{
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
CS("zmt"), std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
+ assert(ss.str() == CS("zmt"));
}
// std::basic_string_view<CharT>
{
const auto csv = SV("zmt");
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- csv, std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
}
// std::basic_string<CharT>
{
const auto cs = ST("zmt");
- const std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
+ std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
}
}
int main(int, char**) {
- test_constraints<char>();
+ test_sfinae<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test_constraints<wchar_t>();
+ test_sfinae<wchar_t>();
test<wchar_t>();
#endif
return 0;
diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
index 501f76d00acfe..949516d061adc 100644
--- a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.string_view.pass.cpp
@@ -25,22 +25,22 @@
#include "test_macros.h"
template <typename S, typename T>
-concept HasMember = requires(S s, const T& sv) {
+concept HasStr = requires(S s, const T& sv) {
{ s.str(sv) };
};
-struct SomeObject {};
-
template <typename CharT>
-void test_constraints() {
- static_assert(HasMember<std::basic_istringstream<CharT>, const CharT*>);
- static_assert(HasMember<std::basic_istringstream<CharT>, std::basic_string_view<CharT>>);
- static_assert(HasMember<std::basic_istringstream<CharT>, std::basic_string<CharT>>);
+void test_sfinae() {
+ struct SomeObject {};
+
+ static_assert(HasStr<std::basic_istringstream<CharT>, const CharT*>);
+ static_assert(HasStr<std::basic_istringstream<CharT>, std::basic_string_view<CharT>>);
+ static_assert(HasStr<std::basic_istringstream<CharT>, std::basic_string<CharT>>);
- static_assert(!HasMember<std::basic_istringstream<CharT>, char>);
- static_assert(!HasMember<std::basic_istringstream<CharT>, int>);
- static_assert(!HasMember<std::basic_istringstream<CharT>, SomeObject>);
- static_assert(!HasMember<std::basic_istringstream<CharT>, std::nullptr_t>);
+ static_assert(!HasStr<std::basic_istringstream<CharT>, char>);
+ static_assert(!HasStr<std::basic_istringstream<CharT>, int>);
+ static_assert(!HasStr<std::basic_istringstream<CharT>, SomeObject>);
+ static_assert(!HasStr<std::basic_istringstream<CharT>, std::nullptr_t>);
}
#define CS(S) MAKE_CSTRING(CharT, S)
@@ -63,10 +63,10 @@ void test() {
}
int main(int, char**) {
- test_constraints<char>();
+ test_sfinae<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test_constraints<wchar_t>();
+ test_sfinae<wchar_t>();
test<wchar_t>();
#endif
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.alloc.pass.cpp
new file mode 100644
index 0000000000000..0b3515dc543b7
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.alloc.pass.cpp
@@ -0,0 +1,114 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_ostringstream(const T& t, const Allocator& a);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT>
+void test_sfinae() {
+ struct SomeObject {};
+ struct NonAllocator {};
+
+ // `const CharT*`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ const test_allocator<CharT>>());
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ test_allocator<CharT>>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ const test_allocator<CharT>>());
+
+ // String-view-like
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ const test_allocator<CharT>>);
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ const test_allocator<CharT>>());
+
+ // Allocator
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const NonAllocator>);
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const NonAllocator>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const test_allocator<CharT> ca;
+
+ // const CharT*
+ {
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+}
+
+int main(int, char**) {
+ test_sfinae<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_sfinae<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.alloc.pass.cpp
index 59659505055f5..b63536f0e0371 100644
--- a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.alloc.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.alloc.pass.cpp
@@ -16,8 +16,8 @@
// template<class T>
// basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a);
-#include <array>
#include <cassert>
+#include <concepts>
#include <sstream>
#include <string>
#include <string_view>
@@ -27,56 +27,80 @@
#include "test_convertible.h"
#include "test_macros.h"
-struct SomeObject {};
-struct NonAllocator {};
-
template <typename CharT>
-void test_constraints() {
+void test_sfinae() {
+ struct SomeObject {};
+ struct NonAllocator {};
+
// `const CharT*`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ test_allocator<CharT>>);
static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
const CharT*,
std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
// `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>);
static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string_view<CharT>,
+ const std::basic_string_view<CharT>,
std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
// `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
static_assert(test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
+ const std::basic_string<CharT>,
std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
- // Non-convertible to std::`basic_string_view<CharT>`
- static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- int,
- std::ios_base::openmode,
- test_allocator<CharT>>());
+ // String-view-like
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- const int&,
- std::ios_base::openmode,
- test_allocator<CharT>>());
- static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- SomeObject,
+ const int,
std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
+
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- const SomeObject&,
+ const SomeObject,
std::ios_base::openmode,
- test_allocator<CharT>>());
+ const test_allocator<CharT>>());
// Mode
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ SomeObject,
+ const NonAllocator>);
static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
+ const std::basic_string_view<CharT>,
SomeObject,
- NonAllocator>());
+ const NonAllocator>());
// Allocator
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ const NonAllocator>);
static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
- std::basic_string<CharT>,
+ const std::basic_string_view<CharT>,
std::ios_base::openmode,
- NonAllocator>());
+ const NonAllocator>());
}
#define CS(S) MAKE_CSTRING(CharT, S)
@@ -85,47 +109,36 @@ void test_constraints() {
template <class CharT>
static void test() {
- using namespace std::string_literals;
- using namespace std::string_view_literals;
+ const test_allocator<CharT> ca;
// const CharT*
{
- const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"));
- assert(ss.view() == SV("zmt"));
- }
- {
- const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- CS("zmt"), std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ CS("zmt"), std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
}
// std::basic_string_view<CharT>
{
- const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(SV("zmt"));
- assert(ss.view() == SV("zmt"));
- }
- {
- const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- SV("zmt"), std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
+ const auto csv = SV("zmt");
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
}
// std::basic_string<CharT>
{
- const std::basic_string<CharT> s(ST("zmt"));
- const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s);
- assert(ss.view() == SV("zmt"));
- }
- {
- const std::basic_string<CharT> s(ST("zmt"));
- const std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s, std::ios_base::binary);
- assert(ss.view() == SV("zmt"));
+ const auto cs = ST("zmt");
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
}
}
int main(int, char**) {
- test_constraints<char>();
+ test_sfinae<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test_constraints<wchar_t>();
+ test_sfinae<wchar_t>();
test<wchar_t>();
#endif
return 0;
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.pass.cpp
new file mode 100644
index 0000000000000..7a87f1bfc73b6
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string_view.mode.pass.cpp
@@ -0,0 +1,116 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_ostringstream(const T& t, ios_base::openmode which);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT>
+void test_sfinae() {
+ struct SomeObject {};
+
+ // `const CharT*`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>>,
+ const CharT*,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>>,
+ const CharT*,
+ std::ios_base::openmode>());
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>>,
+ const std::basic_string_view<CharT, std::char_traits<CharT>>,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>>,
+ const std::basic_string_view<CharT, std::char_traits<CharT>>,
+ std::ios_base::openmode>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode>());
+
+ // String-view-like
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode>());
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode>());
+
+ // Mode
+ static_assert(
+ !std::constructible_from<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const SomeObject>);
+ static_assert(!test_convertible<std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const SomeObject>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ // const CharT*
+ {
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ CS("zmt"), std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ std::basic_ostringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+}
+
+int main(int, char**) {
+ test_sfinae<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_sfinae<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
index 018be464f61d3..d0433c9347aa8 100644
--- a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.string_view.pass.cpp
@@ -25,22 +25,22 @@
#include "test_macros.h"
template <typename S, typename T>
-concept HasMember = requires(S s, const T& sv) {
+concept HasStr = requires(S s, const T& sv) {
{ s.str(sv) };
};
-struct SomeObject {};
-
template <typename CharT>
-void test_constraints() {
- static_assert(HasMember<std::basic_ostringstream<CharT>, const CharT*>);
- static_assert(HasMember<std::basic_ostringstream<CharT>, std::basic_string_view<CharT>>);
- static_assert(HasMember<std::basic_ostringstream<CharT>, std::basic_string<CharT>>);
+void test_sfinae() {
+ struct SomeObject {};
+
+ static_assert(HasStr<std::basic_ostringstream<CharT>, const CharT*>);
+ static_assert(HasStr<std::basic_ostringstream<CharT>, std::basic_string_view<CharT>>);
+ static_assert(HasStr<std::basic_ostringstream<CharT>, std::basic_string<CharT>>);
- static_assert(!HasMember<std::basic_ostringstream<CharT>, char>);
- static_assert(!HasMember<std::basic_ostringstream<CharT>, int>);
- static_assert(!HasMember<std::basic_ostringstream<CharT>, SomeObject>);
- static_assert(!HasMember<std::basic_ostringstream<CharT>, std::nullptr_t>);
+ static_assert(!HasStr<std::basic_ostringstream<CharT>, char>);
+ static_assert(!HasStr<std::basic_ostringstream<CharT>, int>);
+ static_assert(!HasStr<std::basic_ostringstream<CharT>, SomeObject>);
+ static_assert(!HasStr<std::basic_ostringstream<CharT>, std::nullptr_t>);
}
#define CS(S) MAKE_CSTRING(CharT, S)
@@ -63,10 +63,10 @@ void test() {
}
int main(int, char**) {
- test_constraints<char>();
+ test_sfinae<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test_constraints<wchar_t>();
+ test_sfinae<wchar_t>();
test<wchar_t>();
#endif
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.alloc.pass.cpp
new file mode 100644
index 0000000000000..264ed301e9ffd
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.alloc.pass.cpp
@@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_stringbuf(const T& t, const Allocator& a);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT>
+void test_sfinae() {
+ struct SomeObject {};
+ struct NonAllocator {};
+
+ // `const CharT*`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ const test_allocator<CharT>>());
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ test_allocator<CharT>>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ const test_allocator<CharT>>());
+
+ // String-view-like
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ const test_allocator<CharT>>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ const test_allocator<CharT>>());
+
+ // Allocator
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const NonAllocator>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const NonAllocator>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const test_allocator<CharT> ca;
+
+ // const CharT*
+ {
+ const std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.get_allocator() == ca);
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ const std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.get_allocator() == ca);
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ const std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.get_allocator() == ca);
+ }
+}
+
+int main(int, char**) {
+ test_sfinae<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_sfinae<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.alloc.pass.cpp
new file mode 100644
index 0000000000000..872215b5342eb
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.alloc.pass.cpp
@@ -0,0 +1,141 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT>
+void test_sfinae() {
+ struct SomeObject {};
+ struct NonAllocator {};
+
+ // `const CharT*`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+
+ // String-view-like
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+
+ // Mode
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ SomeObject,
+ const NonAllocator>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ SomeObject,
+ const NonAllocator>());
+
+ // Allocator
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ const NonAllocator>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ const NonAllocator>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const test_allocator<CharT> ca;
+
+ // const CharT*
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ CS("zmt"), std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.get_allocator() == ca);
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.get_allocator() == ca);
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.get_allocator() == ca);
+ }
+}
+
+int main(int, char**) {
+ test_sfinae<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_sfinae<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.pass.cpp
new file mode 100644
index 0000000000000..efb63be6bcb6e
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.pass.cpp
@@ -0,0 +1,111 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_stringbuf(const T& t, ios_base::openmode which);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT>
+void test_sfinae() {
+ struct SomeObject {};
+
+ // `const CharT*`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>>,
+ const CharT*,
+ std::ios_base::openmode>);
+ static_assert(
+ !test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>>, const CharT*, std::ios_base::openmode>());
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>>,
+ const std::basic_string_view<CharT, std::char_traits<CharT>>,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>>,
+ const std::basic_string_view<CharT, std::char_traits<CharT>>,
+ std::ios_base::openmode>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode>());
+
+ // String-view-like
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode>());
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode>());
+
+ // Mode
+ static_assert(!std::constructible_from<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const SomeObject>);
+ static_assert(!test_convertible<std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const SomeObject>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ // const CharT*
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+}
+
+int main(int, char**) {
+ test_sfinae<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_sfinae<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
index f0fbc7d273f95..ac76756d0e8a3 100644
--- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string_view.pass.cpp
@@ -24,22 +24,22 @@
#include "test_macros.h"
template <typename S, typename T>
-concept HasMember = requires(S s, const T& sv) {
+concept HasStr = requires(S s, const T& sv) {
{ s.str(sv) };
};
-struct SomeObject {};
-
template <typename CharT>
-void test_constraints() {
- static_assert(HasMember<std::basic_stringbuf<CharT>, const CharT*>);
- static_assert(HasMember<std::basic_stringbuf<CharT>, std::basic_string_view<CharT>>);
- static_assert(HasMember<std::basic_stringbuf<CharT>, std::basic_string<CharT>>);
+void test_sfinae() {
+ struct SomeObject {};
+
+ static_assert(HasStr<std::basic_stringbuf<CharT>, const CharT*>);
+ static_assert(HasStr<std::basic_stringbuf<CharT>, std::basic_string_view<CharT>>);
+ static_assert(HasStr<std::basic_stringbuf<CharT>, std::basic_string<CharT>>);
- static_assert(!HasMember<std::basic_stringbuf<CharT>, char>);
- static_assert(!HasMember<std::basic_stringbuf<CharT>, int>);
- static_assert(!HasMember<std::basic_stringbuf<CharT>, SomeObject>);
- static_assert(!HasMember<std::basic_stringbuf<CharT>, std::nullptr_t>);
+ static_assert(!HasStr<std::basic_stringbuf<CharT>, char>);
+ static_assert(!HasStr<std::basic_stringbuf<CharT>, int>);
+ static_assert(!HasStr<std::basic_stringbuf<CharT>, SomeObject>);
+ static_assert(!HasStr<std::basic_stringbuf<CharT>, std::nullptr_t>);
}
#define CS(S) MAKE_CSTRING(CharT, S)
@@ -62,10 +62,10 @@ void test() {
}
int main(int, char**) {
- test_constraints<char>();
+ test_sfinae<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test_constraints<wchar_t>();
+ test_sfinae<wchar_t>();
test<wchar_t>();
#endif
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.alloc.pass.cpp
new file mode 100644
index 0000000000000..3fe41d57341c3
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.alloc.pass.cpp
@@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_stringstream(const T& t, const Allocator& a);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT>
+void test_sfinae() {
+ struct SomeObject {};
+ struct NonAllocator {};
+
+ // `const CharT*`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ const test_allocator<CharT>>());
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ test_allocator<CharT>>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ const test_allocator<CharT>>());
+
+ // String-view-like
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ const test_allocator<CharT>>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ const test_allocator<CharT>>());
+
+ // Allocator
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const NonAllocator>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const NonAllocator>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const test_allocator<CharT> ca;
+
+ // const CharT*
+ {
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+}
+
+int main(int, char**) {
+ test_sfinae<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_sfinae<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.alloc.pass.cpp
new file mode 100644
index 0000000000000..e0fdcc64c818d
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.alloc.pass.cpp
@@ -0,0 +1,141 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT>
+void test_sfinae() {
+ struct SomeObject {};
+ struct NonAllocator {};
+
+ // `const CharT*`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const CharT*,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+
+ // String-view-like
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode,
+ const test_allocator<CharT>>());
+
+ // Mode
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ SomeObject,
+ const NonAllocator>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ SomeObject,
+ const NonAllocator>());
+
+ // Allocator
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ const NonAllocator>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ std::ios_base::openmode,
+ const NonAllocator>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const test_allocator<CharT> ca;
+
+ // const CharT*
+ {
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ CS("zmt"), std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary, ca);
+ assert(ss.str() == CS("zmt"));
+ assert(ss.rdbuf()->get_allocator() == ca);
+ }
+}
+
+int main(int, char**) {
+ test_sfinae<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_sfinae<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.pass.cpp
new file mode 100644
index 0000000000000..0d5158a97b816
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.pass.cpp
@@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_stringstream(const T& t, ios_base::openmode which);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT>
+void test_sfinae() {
+ struct SomeObject {};
+
+ // `const CharT*`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>>,
+ const CharT*,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>>,
+ const CharT*,
+ std::ios_base::openmode>());
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>>,
+ const std::basic_string_view<CharT, std::char_traits<CharT>>,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>>,
+ const std::basic_string_view<CharT, std::char_traits<CharT>>,
+ std::ios_base::openmode>());
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string<CharT>,
+ std::ios_base::openmode>());
+
+ // String-view-like
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const int,
+ std::ios_base::openmode>());
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const SomeObject,
+ std::ios_base::openmode>());
+
+ // Mode
+ static_assert(!std::constructible_from<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const SomeObject>);
+ static_assert(!test_convertible<std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>,
+ const std::basic_string_view<CharT>,
+ const SomeObject>());
+}
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ // const CharT*
+ {
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+ // std::basic_string_view<CharT>
+ {
+ const auto csv = SV("zmt");
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+ // std::basic_string<CharT>
+ {
+ const auto cs = ST("zmt");
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary);
+ assert(ss.str() == CS("zmt"));
+ }
+}
+
+int main(int, char**) {
+ test_sfinae<char>();
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_sfinae<wchar_t>();
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
index 76c2963580911..f575c2f4d9622 100644
--- a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string_view.pass.cpp
@@ -25,22 +25,22 @@
#include "test_macros.h"
template <typename S, typename T>
-concept HasMember = requires(S s, const T& sv) {
+concept HasStr = requires(S s, const T& sv) {
{ s.str(sv) };
};
-struct SomeObject {};
-
template <typename CharT>
-void test_constraints() {
- static_assert(HasMember<std::basic_stringstream<CharT>, const CharT*>);
- static_assert(HasMember<std::basic_stringstream<CharT>, std::basic_string_view<CharT>>);
- static_assert(HasMember<std::basic_stringstream<CharT>, std::basic_string<CharT>>);
+void test_sfinae() {
+ struct SomeObject {};
+
+ static_assert(HasStr<std::basic_stringstream<CharT>, const CharT*>);
+ static_assert(HasStr<std::basic_stringstream<CharT>, std::basic_string_view<CharT>>);
+ static_assert(HasStr<std::basic_stringstream<CharT>, std::basic_string<CharT>>);
- static_assert(!HasMember<std::basic_stringstream<CharT>, char>);
- static_assert(!HasMember<std::basic_stringstream<CharT>, int>);
- static_assert(!HasMember<std::basic_stringstream<CharT>, SomeObject>);
- static_assert(!HasMember<std::basic_stringstream<CharT>, std::nullptr_t>);
+ static_assert(!HasStr<std::basic_stringstream<CharT>, char>);
+ static_assert(!HasStr<std::basic_stringstream<CharT>, int>);
+ static_assert(!HasStr<std::basic_stringstream<CharT>, SomeObject>);
+ static_assert(!HasStr<std::basic_stringstream<CharT>, std::nullptr_t>);
}
#define CS(S) MAKE_CSTRING(CharT, S)
@@ -63,10 +63,10 @@ void test() {
}
int main(int, char**) {
- test_constraints<char>();
+ test_sfinae<char>();
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
- test_constraints<wchar_t>();
+ test_sfinae<wchar_t>();
test<wchar_t>();
#endif
>From cc51e83dd04b8540d05be68d88c6d3df6ee1357b Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sat, 3 Feb 2024 18:46:15 +0200
Subject: [PATCH 4/5] Done: Implementation and tests
---
libcxx/include/sstream | 32 ++++++++++---------
.../string_view.mode.alloc.pass.cpp | 8 +++--
.../stringbuf.cons/string_view.mode.pass.cpp | 9 ++++--
.../string_view.mode.alloc.pass.cpp | 9 ++++--
.../string_view.mode.pass.cpp | 9 ++++--
5 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/libcxx/include/sstream b/libcxx/include/sstream
index 6f6da1cb9ba07..af026a0a42b9d 100644
--- a/libcxx/include/sstream
+++ b/libcxx/include/sstream
@@ -416,9 +416,9 @@ public:
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
_LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
- : basic_stringbuf(__which, __a) {
+ : __hm_(nullptr), __mode_(__which | ios_base::in | ios_base::out) {
basic_string_view<_CharT, _Traits> __sv = __t;
- __str_ = __sv;
+ __str_ = string_type(__sv, __a);
__init_buf_ptrs();
}
@@ -898,16 +898,17 @@ public:
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in)
- : basic_istringstream(__t, __which, _Allocator()) {}
+ _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in)
+ : basic_istringstream(__t, __which | ios_base::in, _Allocator()) {}
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- basic_istringstream(const _Tp& __t, const _Allocator& __a) : basic_istringstream(__t, ios_base::in, __a) {}
+ _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, const _Allocator& __a)
+ : basic_istringstream(__t, ios_base::in, __a) {}
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
+ _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
: basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {}
#endif // _LIBCPP_STD_VER >= 26
@@ -1031,16 +1032,17 @@ public:
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out)
- : basic_ostringstream(__t, __which, _Allocator()) {}
+ _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out)
+ : basic_ostringstream(__t, __which | ios_base::out, _Allocator()) {}
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- basic_ostringstream(const _Tp& __t, const _Allocator& __a) : basic_ostringstream(__t, ios_base::out, __a) {}
+ _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, const _Allocator& __a)
+ : basic_ostringstream(__t, ios_base::out, __a) {}
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
+ _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
: basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {}
#endif // _LIBCPP_STD_VER >= 26
@@ -1168,19 +1170,19 @@ public:
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- explicit basic_stringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out | ios_base::in)
+ _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const _Tp& __t,
+ ios_base::openmode __which = ios_base::out | ios_base::in)
: basic_stringstream(__t, __which, _Allocator()) {}
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- basic_stringstream(const _Tp& __t, const _Allocator& __a)
+ _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, const _Allocator& __a)
: basic_stringstream(__t, ios_base::out | ios_base::in, __a) {}
template <class _Tp>
requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
- basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
- : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)),
- __sb_(__t, __which | ios_base::out | ios_base::in, __a) {}
+ _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
+ : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which, __a) {}
#endif // _LIBCPP_STD_VER >= 26
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.alloc.pass.cpp
index 872215b5342eb..6f304125babb4 100644
--- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.alloc.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.alloc.pass.cpp
@@ -110,21 +110,23 @@ static void test() {
// const CharT*
{
std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- CS("zmt"), std::ios_base::binary, ca);
+ CS("zmt"), std::ios_base::out | std::ios_base::in, ca);
assert(ss.str() == CS("zmt"));
assert(ss.get_allocator() == ca);
}
// std::basic_string_view<CharT>
{
const auto csv = SV("zmt");
- std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary, ca);
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ csv, std::ios_base::out | std::ios_base::in, ca);
assert(ss.str() == CS("zmt"));
assert(ss.get_allocator() == ca);
}
// std::basic_string<CharT>
{
const auto cs = ST("zmt");
- std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary, ca);
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ cs, std::ios_base::out | std::ios_base::in, ca);
assert(ss.str() == CS("zmt"));
assert(ss.get_allocator() == ca);
}
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.pass.cpp
index efb63be6bcb6e..893a27befb794 100644
--- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string_view.mode.pass.cpp
@@ -83,19 +83,22 @@ template <class CharT>
static void test() {
// const CharT*
{
- std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), std::ios_base::binary);
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ CS("zmt"), std::ios_base::out | std::ios_base::in);
assert(ss.str() == CS("zmt"));
}
// std::basic_string_view<CharT>
{
const auto csv = SV("zmt");
- std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary);
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ csv, std::ios_base::out | std::ios_base::in);
assert(ss.str() == CS("zmt"));
}
// std::basic_string<CharT>
{
const auto cs = ST("zmt");
- std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary);
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ cs, std::ios_base::out | std::ios_base::in);
assert(ss.str() == CS("zmt"));
}
}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.alloc.pass.cpp
index e0fdcc64c818d..be3d5d8b02059 100644
--- a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.alloc.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.alloc.pass.cpp
@@ -102,6 +102,7 @@ void test_sfinae() {
#define CS(S) MAKE_CSTRING(CharT, S)
#define ST(S) MAKE_STRING(CharT, S)
#define SV(S) MAKE_STRING_VIEW(CharT, S)
+#include <print>
template <class CharT>
static void test() {
@@ -110,21 +111,23 @@ static void test() {
// const CharT*
{
std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
- CS("zmt"), std::ios_base::binary, ca);
+ CS("zmt"), std::ios_base::out | std::ios_base::in, ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
}
// std::basic_string_view<CharT>
{
const auto csv = SV("zmt");
- std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary, ca);
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ csv, std::ios_base::out | std::ios_base::in, ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
}
// std::basic_string<CharT>
{
const auto cs = ST("zmt");
- std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary, ca);
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ cs, std::ios_base::out | std::ios_base::in, ca);
assert(ss.str() == CS("zmt"));
assert(ss.rdbuf()->get_allocator() == ca);
}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.pass.cpp
index 0d5158a97b816..e2ad1d447a7e2 100644
--- a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string_view.mode.pass.cpp
@@ -84,19 +84,22 @@ template <class CharT>
static void test() {
// const CharT*
{
- std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(CS("zmt"), std::ios_base::binary);
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ CS("zmt"), std::ios_base::out | std::ios_base::in);
assert(ss.str() == CS("zmt"));
}
// std::basic_string_view<CharT>
{
const auto csv = SV("zmt");
- std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(csv, std::ios_base::binary);
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ csv, std::ios_base::out | std::ios_base::in);
assert(ss.str() == CS("zmt"));
}
// std::basic_string<CharT>
{
const auto cs = ST("zmt");
- std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(cs, std::ios_base::binary);
+ std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(
+ cs, std::ios_base::out | std::ios_base::in);
assert(ss.str() == CS("zmt"));
}
}
>From 3af36e9cefe6f49ed450634b5e671b4e31ff2eb5 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sat, 3 Feb 2024 18:46:54 +0200
Subject: [PATCH 5/5] Generated FTM
---
libcxx/docs/FeatureTestMacroTable.rst | 2 +-
libcxx/include/version | 2 +-
.../sstream.version.compile.pass.cpp | 16 +++++-----------
.../version.version.compile.pass.cpp | 16 +++++-----------
4 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index a5c6fa22cec06..5a0bbf7df0b05 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -440,7 +440,7 @@ Status
--------------------------------------------------- -----------------
``__cpp_lib_span_initializer_list`` ``202311L``
--------------------------------------------------- -----------------
- ``__cpp_lib_sstream_from_string_view`` *unimplemented*
+ ``__cpp_lib_sstream_from_string_view`` ``202306L``
--------------------------------------------------- -----------------
``__cpp_lib_submdspan`` *unimplemented*
--------------------------------------------------- -----------------
diff --git a/libcxx/include/version b/libcxx/include/version
index e4dbb7bdd5fc2..4fbba978b6b0e 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -508,7 +508,7 @@ __cpp_lib_within_lifetime 202306L <type_traits>
// # define __cpp_lib_smart_ptr_owner_equality 202306L
# define __cpp_lib_span_at 202311L
# define __cpp_lib_span_initializer_list 202311L
-// # define __cpp_lib_sstream_from_string_view 202306L
+# define __cpp_lib_sstream_from_string_view 202306L
// # define __cpp_lib_submdspan 202306L
// # define __cpp_lib_text_encoding 202306L
# undef __cpp_lib_to_chars
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/sstream.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/sstream.version.compile.pass.cpp
index 78e17e5f1ddb5..ad3c8e4012ecf 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/sstream.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/sstream.version.compile.pass.cpp
@@ -56,17 +56,11 @@
#elif TEST_STD_VER > 23
-# if !defined(_LIBCPP_VERSION)
-# ifndef __cpp_lib_sstream_from_string_view
-# error "__cpp_lib_sstream_from_string_view should be defined in c++26"
-# endif
-# if __cpp_lib_sstream_from_string_view != 202306L
-# error "__cpp_lib_sstream_from_string_view should have the value 202306L in c++26"
-# endif
-# else // _LIBCPP_VERSION
-# ifdef __cpp_lib_sstream_from_string_view
-# error "__cpp_lib_sstream_from_string_view should not be defined because it is unimplemented in libc++!"
-# endif
+# ifndef __cpp_lib_sstream_from_string_view
+# error "__cpp_lib_sstream_from_string_view should be defined in c++26"
+# endif
+# if __cpp_lib_sstream_from_string_view != 202306L
+# error "__cpp_lib_sstream_from_string_view should have the value 202306L in c++26"
# endif
#endif // TEST_STD_VER > 23
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index 29f0ba89330bb..60c43b7eb082d 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -7315,17 +7315,11 @@
# error "__cpp_lib_ssize should have the value 201902L in c++26"
# endif
-# if !defined(_LIBCPP_VERSION)
-# ifndef __cpp_lib_sstream_from_string_view
-# error "__cpp_lib_sstream_from_string_view should be defined in c++26"
-# endif
-# if __cpp_lib_sstream_from_string_view != 202306L
-# error "__cpp_lib_sstream_from_string_view should have the value 202306L in c++26"
-# endif
-# else // _LIBCPP_VERSION
-# ifdef __cpp_lib_sstream_from_string_view
-# error "__cpp_lib_sstream_from_string_view should not be defined because it is unimplemented in libc++!"
-# endif
+# ifndef __cpp_lib_sstream_from_string_view
+# error "__cpp_lib_sstream_from_string_view should be defined in c++26"
+# endif
+# if __cpp_lib_sstream_from_string_view != 202306L
+# error "__cpp_lib_sstream_from_string_view should have the value 202306L in c++26"
# endif
# if !defined(_LIBCPP_VERSION)
More information about the libcxx-commits
mailing list