diff --git a/libcxx/docs/Status/Cxx20.rst b/libcxx/docs/Status/Cxx20.rst --- a/libcxx/docs/Status/Cxx20.rst +++ b/libcxx/docs/Status/Cxx20.rst @@ -49,7 +49,7 @@ .. [#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: Only `view()` members implemented. + .. [#note-P0408] P0408: All `stringbuf` members and `view()` in all classes implemented. .. [#note-P0660] P0660: Section 32.3 Stop Tokens is complete. ``jthread`` hasn't been implemented yet. .. _issues-status-cxx20: diff --git a/libcxx/include/sstream b/libcxx/include/sstream --- a/libcxx/include/sstream +++ b/libcxx/include/sstream @@ -30,18 +30,41 @@ explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20 basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20 explicit basic_stringbuf(ios_base::openmode which); // C++20 - explicit basic_stringbuf(const basic_string& str, + explicit basic_stringbuf(const basic_string& s, ios_base::openmode which = ios_base::in | ios_base::out); + explicit basic_stringbuf(const allocator_type& a) + : basic_stringbuf(ios_base::in | ios_base::out, a) {} // C++20 + basic_stringbuf(ios_base::openmode which, const allocator_type& a); // C++20 + explicit basic_stringbuf(basic_string&& s, + ios_base::openmode which = ios_base::in | ios_base::out); // C++20 + template + basic_stringbuf(const basic_string& s, const allocator_type& a) + : basic_stringbuf(s, ios_base::in | ios_base::out, a) {} // C++20 + template + basic_stringbuf(const basic_string& s, + ios_base::openmode which, const allocator_type& a); // C++20 + template + explicit basic_stringbuf(const basic_string& s, + ios_base::openmode which = ios_base::in | ios_base::out); // C++20 basic_stringbuf(basic_stringbuf&& rhs); + basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20 // [stringbuf.assign] Assign and swap: basic_stringbuf& operator=(basic_stringbuf&& rhs); void swap(basic_stringbuf& rhs) noexcept(see below); // conditionally noexcept since C++20 // [stringbuf.members] Member functions: - basic_string str() const; + allocator_type get_allocator() const noexcept; // C++20 + basic_string str() const; // before C++20 + basic_string str() const &; // C++20 + template + basic_string str(const SAlloc& sa) const; // C++20 + basic_string str() &&; // C++20 + basic_string_view view() const noexcept; // C++20 void str(const basic_string& s); - basic_string_view view() const noexcept; // C++20 + template + void str(const basic_string& s); // C++20 + void str(basic_string&& s); // C++20 protected: // [stringbuf.virtuals] Overridden virtual functions: @@ -229,6 +252,8 @@ string_type __str_; mutable char_type* __hm_; ios_base::openmode __mode_; + _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs(); + _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs); public: // [stringbuf.cons] constructors: @@ -248,7 +273,48 @@ str(__s); } - basic_stringbuf(basic_stringbuf&& __rhs); +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a) + : basic_stringbuf(ios_base::in | ios_base::out, __a) {} + + _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a) + : __str_(__a), __hm_(nullptr), __mode_(__wch) {} + + _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s, + ios_base::openmode __wch = ios_base::in | ios_base::out) + : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) { + __init_buf_ptrs(); + } + + template + _LIBCPP_HIDE_FROM_ABI + basic_stringbuf(const basic_string& __s, const allocator_type& __a) + : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {} + + template + _LIBCPP_HIDE_FROM_ABI basic_stringbuf( + const basic_string& __s, ios_base::openmode __wch, const allocator_type& __a) + : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) { + __init_buf_ptrs(); + } + + template + requires (!is_same_v<_SAlloc, allocator_type>) + _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string& __s, + ios_base::openmode __wch = ios_base::in | ios_base::out) + : __str_(__s), __hm_(nullptr), __mode_(__wch) { + __init_buf_ptrs(); + } +#endif // _LIBCPP_STD_VER >= 20 + + basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); } + +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a) + : basic_stringbuf(__rhs.__mode_, __a) { + __move_init(std::move(__rhs)); + } +#endif // [stringbuf.assign] Assign and swap: basic_stringbuf& operator=(basic_stringbuf&& __rhs); @@ -260,13 +326,54 @@ ; // [stringbuf.members] Member functions: + +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); } +#endif + +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) string_type str() const; - void str(const string_type& __s); +#else + _LIBCPP_HIDE_FROM_ABI string_type str() const & { return str(__str_.get_allocator()); } + + template + requires __is_allocator<_SAlloc>::value + _LIBCPP_HIDE_FROM_ABI basic_string str(const _SAlloc& __sa) const { + return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa); + } + + _LIBCPP_HIDE_FROM_ABI string_type str() && { + const basic_string_view<_CharT, _Traits> __view = view(); + string_type __result(std::move(__str_), __view.data() - __str_.data(), __view.size()); + __str_.clear(); + __init_buf_ptrs(); + return __result; + } +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) + #if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI - basic_string_view view() const noexcept; + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept; #endif + void str(const string_type& __s) { + __str_ = __s; + __init_buf_ptrs(); + } + +#if _LIBCPP_STD_VER >= 20 + template + requires (!is_same_v<_SAlloc, allocator_type>) + _LIBCPP_HIDE_FROM_ABI void str(const basic_string& __s) { + __str_ = __s; + __init_buf_ptrs(); + } + + _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { + __str_ = std::move(__s); + __init_buf_ptrs(); + } +#endif // _LIBCPP_STD_VER >= 20 + protected: // [stringbuf.virtuals] Overridden virtual functions: int_type underflow() override; @@ -282,9 +389,7 @@ }; template -basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs) - : __mode_(__rhs.__mode_) -{ +_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) { char_type* __p = const_cast(__rhs.__str_.data()); ptrdiff_t __binp = -1; ptrdiff_t __ninp = -1; @@ -463,49 +568,35 @@ __x.swap(__y); } +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) template basic_string<_CharT, _Traits, _Allocator> -basic_stringbuf<_CharT, _Traits, _Allocator>::str() const -{ -#if _LIBCPP_STD_VER >= 20 - return string_type(view(), __str_.get_allocator()); -#else // _LIBCPP_STD_VER >= 20 - if (__mode_ & ios_base::out) - { +basic_stringbuf<_CharT, _Traits, _Allocator>::str() const { + if (__mode_ & ios_base::out) { if (__hm_ < this->pptr()) __hm_ = this->pptr(); return string_type(this->pbase(), __hm_, __str_.get_allocator()); - } - else if (__mode_ & ios_base::in) + } else if (__mode_ & ios_base::in) return string_type(this->eback(), this->egptr(), __str_.get_allocator()); return string_type(__str_.get_allocator()); -#endif // _LIBCPP_STD_VER >= 20 } +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) template -void -basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s) -{ - __str_ = __s; +_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() { __hm_ = nullptr; - if (__mode_ & ios_base::in) - { - __hm_ = const_cast(__str_.data()) + __str_.size(); - this->setg(const_cast(__str_.data()), - const_cast(__str_.data()), - __hm_); - } - if (__mode_ & ios_base::out) - { + char_type* __data = const_cast(__str_.data()); typename string_type::size_type __sz = __str_.size(); - __hm_ = const_cast(__str_.data()) + __sz; + if (__mode_ & ios_base::in) { + __hm_ = __data + __sz; + this->setg(__data, __data, __hm_); + } + if (__mode_ & ios_base::out) { + __hm_ = __data + __sz; __str_.resize(__str_.capacity()); - this->setp(const_cast(__str_.data()), - const_cast(__str_.data()) + __str_.size()); - if (__mode_ & (ios_base::app | ios_base::ate)) - { - while (__sz > INT_MAX) - { + this->setp(__data, __data + __str_.size()); + if (__mode_ & (ios_base::app | ios_base::ate)) { + while (__sz > INT_MAX) { this->pbump(INT_MAX); __sz -= INT_MAX; } diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/alloc.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// template , class Allocator = allocator> +// class basic_stringbuf + +// explicit basic_stringbuf(const Allocator& a) +// : basic_stringbuf(ios_base::in | ios_base::out, a) {} + +#include +#include + +#include "test_allocator.h" +#include "test_macros.h" + +template +static void test() { + const test_allocator a(1); + const std::basic_stringbuf, test_allocator> buf(a); + assert(buf.get_allocator() == a); + assert(buf.view().empty()); +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/mode.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.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 + +// + +// template , class Allocator = allocator> +// class basic_stringbuf + +// basic_stringbuf(ios_base::openmode which, const Allocator& a); + +#include +#include + +#include "test_allocator.h" +#include "test_macros.h" + +template +static void test() { + const test_allocator a(2); + const std::basic_stringbuf, test_allocator> buf(std::ios_base::in, a); + assert(buf.get_allocator() == a); + assert(buf.view().empty()); +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/move.alloc.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// template , class Allocator = allocator> +// class basic_stringbuf + +// basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a); + +#include +#include + +#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 +static void test() { + std::basic_stringbuf, test_allocator> buf1(STR("testing")); + const test_allocator a(2); + const std::basic_stringbuf, test_allocator> buf(std::move(buf1), a); + assert(buf.get_allocator() == a); + assert(buf.view() == SV("testing")); +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string-alloc.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string-alloc.mode.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string-alloc.mode.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// template , class Allocator = allocator> +// class basic_stringbuf + +// template +// explicit basic_stringbuf(const basic_string& s, +// ios_base::openmode which = ios_base::in | ios_base::out); + +#include +#include + +#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 +static void test() { + const std::basic_string, test_allocator> s(STR("testing")); + const std::basic_stringbuf buf(s, std::ios_base::in); + assert(buf.view() == SV("testing")); +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.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 + +// + +// template , class Allocator = allocator> +// class basic_stringbuf + +// template +// basic_stringbuf(const basic_string& s, const Allocator& a) +// : basic_stringbuf(s, ios_base::in | ios_base::out, a) {} + +#include +#include + +#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 +static void test() { + const std::basic_string s(STR("testing")); + const test_allocator a(2); + const std::basic_stringbuf, test_allocator> buf(s, a); + assert(buf.get_allocator() == a); + assert(buf.view() == SV("testing")); +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.mode.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.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 + +// + +// template , class Allocator = allocator> +// class basic_stringbuf + +// template +// basic_stringbuf(const basic_string& s, ios_base::openmode which, const Allocator& a); + +#include +#include + +#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 +static void test() { + const std::basic_string s(STR("testing")); + const test_allocator a(2); + const std::basic_stringbuf, test_allocator> buf(s, std::ios_base::in, a); + assert(buf.get_allocator() == a); + assert(buf.view() == SV("testing")); +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.move.mode.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.move.mode.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.move.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 + +// + +// template , class Allocator = allocator> +// class basic_stringbuf + +// explicit basic_stringbuf(basic_string&& s, ios_base::openmode which = ios_base::in | ios_base::out); + +#include +#include + +#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 +static void test() { + { + std::basic_string s(STR("testing")); + const std::basic_stringbuf, test_allocator> buf(std::move(s)); + assert(buf.view() == SV("testing")); + } + { + std::basic_string s(STR("testing")); + const std::basic_stringbuf, test_allocator> buf( + std::move(s), std::ios_base::out); + assert(buf.view() == SV("testing")); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.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 + +// + +// template , class Allocator = allocator > +// class basic_stringbuf + +// template +// basic_string str(const SAlloc& sa) const; + +#include +#include + +#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 +static void test() { + const std::basic_stringbuf buf(STR("testing")); + const test_allocator a(1); + const std::basic_string, test_allocator> s = buf.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.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 + +// + +// template , class Allocator = allocator > +// class basic_stringbuf + +// basic_string str() &&; + +#include +#include + +#include "make_string.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) + +template +static void test() { + { + std::basic_stringbuf buf(STR("testing")); + std::basic_string s = std::move(buf).str(); + assert(s == STR("testing")); + assert(buf.view().empty()); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string-alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string-alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string-alloc.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 + +// + +// template , class Allocator = allocator > +// class basic_stringbuf + +// template +// void str(const basic_string& s); + +#include +#include + +#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 +static void test() { + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + std::basic_stringbuf buf; + buf.str(s); + assert(buf.view() == SV("testing")); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.string.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.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 + +// + +// template , class Allocator = allocator > +// class basic_stringbuf + +// void str(basic_string&& s); + +#include +#include + +#include "make_string.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) + +template +static void test() { + { + std::basic_stringbuf buf; + std::basic_string s(STR("testing")); + buf.str(std::move(s)); + assert(buf.str() == STR("testing")); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +}