[libcxx-commits] [libcxx] c7c0095 - [libc++] Implement stringstream members of P0408R7 (Efficient Access to basic_stringbuf's Buffer)
Piotr Fusik via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jul 16 09:33:01 PDT 2023
Author: Piotr Fusik
Date: 2023-07-16T18:32:56+02:00
New Revision: c7c0095b29283c65937e8571f23823b164431595
URL: https://github.com/llvm/llvm-project/commit/c7c0095b29283c65937e8571f23823b164431595
DIFF: https://github.com/llvm/llvm-project/commit/c7c0095b29283c65937e8571f23823b164431595.diff
LOG: [libc++] Implement stringstream members of P0408R7 (Efficient Access to basic_stringbuf's Buffer)
Reviewed By: Mordante, #libc
Differential Revision: https://reviews.llvm.org/D155359
Added:
libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/mode.alloc.pass.cpp
libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string-alloc.mode.pass.cpp
libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.alloc.pass.cpp
libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.mode.alloc.pass.cpp
libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.move.mode.pass.cpp
libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.alloc.pass.cpp
libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.move.pass.cpp
libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string-alloc.pass.cpp
libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string.move.pass.cpp
Modified:
libcxx/docs/Status/Cxx20.rst
libcxx/docs/Status/Cxx20Papers.csv
libcxx/include/sstream
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx20.rst b/libcxx/docs/Status/Cxx20.rst
index 5b6b7920df9557..c945ce3c374817 100644
--- a/libcxx/docs/Status/Cxx20.rst
+++ b/libcxx/docs/Status/Cxx20.rst
@@ -49,7 +49,6 @@ Paper Status
.. [#note-P0883.1] P0883: shared_ptr and floating-point changes weren't applied as they themselves aren't implemented yet.
.. [#note-P0883.2] P0883: ``ATOMIC_FLAG_INIT`` was marked deprecated in version 14.0, but was undeprecated with the implementation of LWG3659 in version 15.0.
.. [#note-P2231] P2231: Optional is complete. The changes to variant haven't been implemented yet.
- .. [#note-P0408] P0408: Implemented all `stringbuf`/`istringstream`/`ostringstream` members and `view()` in `stringstream`.
.. [#note-P0660] P0660: Section 32.3 Stop Tokens is complete. ``jthread`` hasn't been implemented yet.
.. _issues-status-cxx20:
diff --git a/libcxx/docs/Status/Cxx20Papers.csv b/libcxx/docs/Status/Cxx20Papers.csv
index 52c4efdad01859..7d65b419028baf 100644
--- a/libcxx/docs/Status/Cxx20Papers.csv
+++ b/libcxx/docs/Status/Cxx20Papers.csv
@@ -99,7 +99,7 @@
"`P1464R1 <https://wg21.link/P1464R1>`__","LWG","Mandating the Standard Library: Clause 22 - Iterators library","Kona","|Complete|","9.0"
"","","","","","",""
"`P0325R4 <https://wg21.link/P0325R4>`__","LWG","to_array from LFTS with updates","Cologne","|Complete|","10.0"
-"`P0408R7 <https://wg21.link/P0408R7>`__","LWG","Efficient Access to basic_stringbuf's Buffer","Cologne","|In Progress| [#note-P0408]_",""
+"`P0408R7 <https://wg21.link/P0408R7>`__","LWG","Efficient Access to basic_stringbuf's Buffer","Cologne","|Complete|","17.0"
"`P0466R5 <https://wg21.link/P0466R5>`__","LWG","Layout-compatibility and Pointer-interconvertibility Traits","Cologne","",""
"`P0553R4 <https://wg21.link/P0553R4>`__","LWG","Bit operations","Cologne","|Complete|","9.0"
"`P0631R8 <https://wg21.link/P0631R8>`__","LWG","Math Constants","Cologne","|Complete|","11.0"
diff --git a/libcxx/include/sstream b/libcxx/include/sstream
index 342e0242fbe551..d4256877782ff5 100644
--- a/libcxx/include/sstream
+++ b/libcxx/include/sstream
@@ -221,9 +221,20 @@ public:
explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20
basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20
explicit basic_stringstream(ios_base::openmode which); // C++20
-
- explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& str,
- ios_base::openmode which = ios_base::out|ios_base::in);
+ explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& s,
+ ios_base::openmode which = ios_base::out | ios_base::in);
+ basic_stringstream(ios_base::openmode which, const allocator_type& a); // C++20
+ explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s,
+ ios_base::openmode which = ios_base::out | ios_base::in); // C++20
+ template <class SAlloc>
+ basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
+ : basic_stringstream(s, ios_base::out | ios_base::in, a) {} // C++20
+ template <class SAlloc>
+ basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s,
+ ios_base::openmode which, const allocator_type& a); // C++20
+ 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
basic_stringstream(basic_stringstream&& rhs);
// [stringstream.assign] Assign and swap:
@@ -232,9 +243,16 @@ public:
// [stringstream.members] Member functions:
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
- basic_string<char_type, traits_type, allocator_type> str() const;
- void str(const basic_string<char_type, traits_type, allocator_type>& str);
- basic_string_view<char_type, traits_type> view() const noexcept; // C++20
+ basic_string<char_type, traits_type, allocator_type> str() const; // before C++20
+ basic_string<char_type, traits_type, allocator_type> str() const &; // C++20
+ template <class SAlloc>
+ basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20
+ basic_string<char_type, traits_type, allocator_type> str() &&; // C++20
+ basic_string_view<char_type, traits_type> view() const noexcept; // C++20
+ void str(const basic_string<char_type, traits_type, allocator_type>& s);
+ 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 charT, class traits, class Allocator>
@@ -1070,6 +1088,29 @@ public:
, __sb_(__s, __wch)
{ }
+#if _LIBCPP_STD_VER >= 20
+ _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a)
+ : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {}
+
+ _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out | ios_base::in)
+ : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {}
+
+ template <class _SAlloc>
+ _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
+ : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {}
+
+ template <class _SAlloc>
+ _LIBCPP_HIDE_FROM_ABI basic_stringstream(
+ const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
+ : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {}
+
+ template <class _SAlloc>
+ requires (!is_same_v<_SAlloc, allocator_type>)
+ _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
+ ios_base::openmode __wch = ios_base::out | ios_base::in)
+ : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
+#endif // _LIBCPP_STD_VER >= 20
+
_LIBCPP_INLINE_VISIBILITY
basic_stringstream(basic_stringstream&& __rhs)
: basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs))
@@ -1095,20 +1136,33 @@ public:
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
}
- _LIBCPP_INLINE_VISIBILITY
- string_type str() const {
- return __sb_.str();
- }
- _LIBCPP_INLINE_VISIBILITY
- void str(const string_type& __s) {
- __sb_.str(__s);
+
+#if _LIBCPP_STD_VER >= 20
+ _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); }
+
+ template <class _SAlloc>
+ requires __is_allocator<_SAlloc>::value
+ _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
+ return __sb_.str(__sa);
}
+
+ _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
+
+ _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
+#else // _LIBCPP_STD_VER >= 20
+ _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
+#endif // _LIBCPP_STD_VER >= 20
+
+ _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
+
#if _LIBCPP_STD_VER >= 20
- _LIBCPP_HIDE_FROM_ABI
- basic_string_view<char_type, traits_type> view() const noexcept {
- return __sb_.view();
+ template <class _SAlloc>
+ _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
+ __sb_.str(__s);
}
-#endif
+
+ _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
+#endif // _LIBCPP_STD_VER >= 20
};
template <class _CharT, class _Traits, class _Allocator>
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/mode.alloc.pass.cpp
new file mode 100644
index 00000000000000..72e5a7f41287f4
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/mode.alloc.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// basic_stringstream(ios_base::openmode which, const Allocator& a);
+
+#include <sstream>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "test_macros.h"
+
+template <class CharT>
+static void test() {
+ const test_allocator<CharT> a(2);
+ const std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(std::ios_base::in, a);
+ assert(ss.rdbuf()->get_allocator() == a);
+ assert(ss.view().empty());
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string-alloc.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string-alloc.mode.pass.cpp
new file mode 100644
index 00000000000000..19fb32fe6e86cf
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string-alloc.mode.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// 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)
+
+#include <sstream>
+#include <cassert>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_macros.h"
+
+#define STR(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ {
+ const std::basic_string<CharT> s(STR("testing"));
+ const std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s);
+ assert(ss.view() == SV("testing"));
+ }
+ {
+ const std::basic_string<CharT> s(STR("testing"));
+ const std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s, std::ios_base::in);
+ assert(ss.view() == SV("testing"));
+ }
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.alloc.pass.cpp
new file mode 100644
index 00000000000000..91f34a8c1e533a
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.alloc.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template <class SAlloc>
+// basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, const Allocator& a)
+// : basic_stringstream(s, ios_base::out | ios_base::in, a) {}
+
+#include <sstream>
+#include <cassert>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_macros.h"
+
+#define STR(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const std::basic_string<CharT> s(STR("testing"));
+ const test_allocator<CharT> a(2);
+ const std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s, a);
+ assert(ss.rdbuf()->get_allocator() == a);
+ assert(ss.view() == SV("testing"));
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.mode.alloc.pass.cpp
new file mode 100644
index 00000000000000..c1bcccdd2df80a
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.mode.alloc.pass.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template <class SAlloc>
+// basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, ios_base::openmode which, const Allocator& a)
+
+#include <sstream>
+#include <cassert>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_macros.h"
+
+#define STR(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const std::basic_string<CharT> s(STR("testing"));
+ const test_allocator<CharT> a(2);
+ const std::basic_stringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>> ss(s, std::ios_base::out, a);
+ assert(ss.rdbuf()->get_allocator() == a);
+ assert(ss.view() == SV("testing"));
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.move.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.move.mode.pass.cpp
new file mode 100644
index 00000000000000..d0146f0ccc2714
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.move.mode.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s, ios_base::openmode which = ios_base::out | ios_base::in);
+
+#include <sstream>
+#include <cassert>
+
+#include "make_string.h"
+#include "test_macros.h"
+
+#define STR(S) MAKE_STRING(CharT, S)
+
+template <class CharT>
+static void test() {
+ {
+ std::basic_string<CharT> s(STR("testing"));
+ const std::basic_stringstream<CharT> ss(std::move(s));
+ assert(ss.str() == STR("testing"));
+ }
+ {
+ std::basic_string<CharT> s(STR("testing"));
+ const std::basic_stringstream<CharT> ss(std::move(s), std::ios_base::out);
+ assert(ss.str() == STR("testing"));
+ }
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.alloc.pass.cpp
new file mode 100644
index 00000000000000..9a1da94948afba
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.alloc.pass.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template <class SAlloc>
+// basic_string<charT, traits, SAlloc> str(const SAlloc& sa) const;
+
+#include <sstream>
+#include <cassert>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_macros.h"
+
+#define STR(S) MAKE_STRING(CharT, S)
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+static void test() {
+ const std::basic_stringstream<CharT> ss(STR("testing"));
+ const test_allocator<CharT> a(1);
+ const std::basic_string<CharT, std::char_traits<CharT>, test_allocator<CharT>> s = ss.str(a);
+ assert(s == SV("testing"));
+ assert(s.get_allocator() == a);
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.move.pass.cpp
new file mode 100644
index 00000000000000..a6b8ec6c37ebaf
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.move.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// basic_string<charT, traits, Allocator> str() &&;
+
+#include <sstream>
+#include <cassert>
+
+#include "make_string.h"
+#include "test_macros.h"
+
+#define STR(S) MAKE_STRING(CharT, S)
+
+template <class CharT>
+static void test() {
+ {
+ std::basic_stringstream<CharT> ss(STR("testing"));
+ std::basic_string<CharT> s = std::move(ss).str();
+ assert(s == STR("testing"));
+ assert(ss.view().empty());
+ }
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string-alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string-alloc.pass.cpp
new file mode 100644
index 00000000000000..4b03609f3a8d9c
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string-alloc.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template <class SAlloc>
+// void str(const basic_string<charT, traits, SAlloc>& s);
+
+#include <sstream>
+#include <cassert>
+
+#include "make_string.h"
+#include "test_allocator.h"
+#include "test_macros.h"
+
+#define STR(S) MAKE_STRING(CharT, S)
+
+template <class CharT>
+static void test() {
+ {
+ const test_allocator<CharT> a(6);
+ const std::basic_string<CharT, std::char_traits<CharT>, test_allocator<CharT>> s(STR("testing"), a);
+ std::basic_stringstream<CharT> ss;
+ ss.str(s);
+ assert(ss.str() == STR("testing"));
+ }
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string.move.pass.cpp
new file mode 100644
index 00000000000000..9c6e2d7fe1879c
--- /dev/null
+++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.string.move.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// void str(basic_string<charT, traits, Allocator>&& s);
+
+#include <sstream>
+#include <cassert>
+
+#include "make_string.h"
+#include "test_macros.h"
+
+#define STR(S) MAKE_STRING(CharT, S)
+
+template <class CharT>
+static void test() {
+ {
+ std::basic_stringstream<CharT> ss;
+ std::basic_string<CharT> s(STR("testing"));
+ ss.str(std::move(s));
+ assert(ss.str() == STR("testing"));
+ }
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
More information about the libcxx-commits
mailing list