1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
13 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
14 // class basic_ostringstream
16 // basic_string<charT, traits, Allocator> str() &&;
21 #include "make_string.h"
22 #include "test_macros.h"
24 #define STR(S) MAKE_STRING(CharT, S)
26 template <class CharT
>
29 std::basic_ostringstream
<CharT
> ss(STR("testing"));
30 std::basic_string
<CharT
> s
= std::move(ss
).str();
31 assert(s
== STR("testing"));
32 assert(ss
.view().empty());
35 std::basic_ostringstream
<CharT
> ss
;
36 std::basic_string
<CharT
> s
= std::move(ss
).str();
38 assert(ss
.view().empty());
41 std::basic_ostringstream
<CharT
> ss(
42 STR("a very long string that exceeds the small string optimization buffer length"));
43 const CharT
* p
= ss
.view().data();
44 std::basic_string
<CharT
> s
= std::move(ss
).str();
45 assert(s
.data() == p
); // the allocation was pilfered
46 assert(ss
.view().empty());
50 int main(int, char**) {
52 #ifndef TEST_HAS_NO_WIDE_CHARACTERS