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: Only `view()`, `get_allocator()` members and some constructor overloads 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,8 +30,11 @@ 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 basic_stringbuf(basic_stringbuf&& rhs); // [stringbuf.assign] Assign and swap: @@ -39,9 +42,10 @@ void swap(basic_stringbuf& rhs); // [stringbuf.members] Member functions: + allocator_type get_allocator() const noexcept; // C++20 basic_string str() const; + basic_string_view view() const noexcept; // C++20 void str(const basic_string& s); - basic_string_view view() const noexcept; // C++20 protected: // [stringbuf.virtuals] Overridden virtual functions: @@ -77,12 +81,13 @@ typedef Allocator allocator_type; // [istringstream.cons] Constructors: - explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 - basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 - explicit basic_istringstream(ios_base::openmode which); // C++20 + explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 + basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 + explicit basic_istringstream(ios_base::openmode which); // C++20 - explicit basic_istringstream(const basic_string& str, + explicit basic_istringstream(const basic_string& s, ios_base::openmode which = ios_base::in); + basic_istringstream(ios_base::openmode which, const allocator_type& a); // C++20 basic_istringstream(basic_istringstream&& rhs); // [istringstream.assign] Assign and swap: @@ -92,8 +97,8 @@ // [istringstream.members] Member functions: basic_stringbuf* rdbuf() const; basic_string str() const; + basic_string_view view() const noexcept; // C++20 void str(const basic_string& s); - basic_string_view view() const noexcept; // C++20 }; template @@ -118,12 +123,13 @@ typedef Allocator allocator_type; // [ostringstream.cons] Constructors: - explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 - basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 - explicit basic_ostringstream(ios_base::openmode which); // C++20 + explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 + basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 + explicit basic_ostringstream(ios_base::openmode which); // C++20 - explicit basic_ostringstream(const basic_string& str, + explicit basic_ostringstream(const basic_string& s, ios_base::openmode which = ios_base::out); + basic_ostringstream(ios_base::openmode which, const allocator_type& a); // C++20 basic_ostringstream(basic_ostringstream&& rhs); // [ostringstream.assign] Assign and swap: @@ -133,8 +139,8 @@ // [ostringstream.members] Member functions: basic_stringbuf* rdbuf() const; basic_string str() const; + basic_string_view view() const noexcept; // C++20 void str(const basic_string& s); - basic_string_view view() const noexcept; // C++20 }; template @@ -163,8 +169,9 @@ 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& str, - ios_base::openmode which = ios_base::out|ios_base::in); + explicit basic_stringstream(const basic_string& s, + ios_base::openmode which = ios_base::out | ios_base::in); + basic_stringstream(ios_base::openmode which, const allocator_type& a); // C++20 basic_stringstream(basic_stringstream&& rhs); // [stringstream.assign] Assign and swap: @@ -174,8 +181,8 @@ // [stringstream.members] Member functions: basic_stringbuf* rdbuf() const; basic_string str() const; + basic_string_view view() const noexcept; // C++20 void str(const basic_string& str); - basic_string_view view() const noexcept; // C++20 }; template @@ -248,6 +255,14 @@ str(__s); } +#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) {} +#endif + basic_stringbuf(basic_stringbuf&& __rhs); // [stringbuf.assign] Assign and swap: @@ -256,12 +271,15 @@ // [stringbuf.members] Member functions: string_type str() const; - void str(const string_type& __s); + #if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI - basic_string_view view() const noexcept; + _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); } + + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept; #endif + void str(const string_type& __s); + protected: // [stringbuf.virtuals] Overridden virtual functions: int_type underflow() override; @@ -687,6 +705,11 @@ , __sb_(__s, __wch | ios_base::in) { } +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a) + : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in, __a) {} +#endif + _LIBCPP_INLINE_VISIBILITY basic_istringstream(basic_istringstream&& __rhs) : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) @@ -716,16 +739,15 @@ 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 - basic_string_view view() const noexcept { + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } #endif + _LIBCPP_INLINE_VISIBILITY + void str(const string_type& __s) { + __sb_.str(__s); + } }; template @@ -773,6 +795,11 @@ , __sb_(__s, __wch | ios_base::out) { } +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a) + : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::out, __a) {} +#endif + _LIBCPP_INLINE_VISIBILITY basic_ostringstream(basic_ostringstream&& __rhs) : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)) @@ -803,16 +830,15 @@ 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 - basic_string_view view() const noexcept { + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } #endif + _LIBCPP_INLINE_VISIBILITY + void str(const string_type& __s) { + __sb_.str(__s); + } }; template @@ -860,6 +886,11 @@ , __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>(&__sb_), __sb_(__wch, __a) {} +#endif + _LIBCPP_INLINE_VISIBILITY basic_stringstream(basic_stringstream&& __rhs) : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)) @@ -889,16 +920,15 @@ 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 - basic_string_view view() const noexcept { + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } #endif + _LIBCPP_INLINE_VISIBILITY + void str(const string_type& __s) { + __sb_.str(__s); + } }; template diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/mode.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.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_istringstream + +// basic_istringstream(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_istringstream, test_allocator> ss(std::ios_base::in, a); + assert(ss.rdbuf()->get_allocator() == a); + assert(ss.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/ostringstream/ostringstream.cons/mode.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/mode.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.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_ostringstream + +// basic_ostringstream(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_ostringstream, test_allocator> ss(std::ios_base::out, a); + assert(ss.rdbuf()->get_allocator() == a); + assert(ss.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/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/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 --- /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 + +// + +// template , class Allocator = allocator > +// class basic_stringstream + +// basic_stringstream(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_stringstream, test_allocator> ss(std::ios_base::in, a); + assert(ss.rdbuf()->get_allocator() == a); + assert(ss.view().empty()); +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +}