1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 
11 // <sstream>
12 
13 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
14 // class basic_ostringstream
15 
16 // explicit basic_ostringstream(basic_string<char_type, traits_type, allocator_type>&& s, ios_base::openmode which = ios_base::out);
17 
18 #include <sstream>
19 #include <cassert>
20 
21 #include "make_string.h"
22 #include "test_allocator.h"
23 #include "test_macros.h"
24 #include "operator_hijacker.h"
25 
26 #define STR(S) MAKE_STRING(CharT, S)
27 #define SV(S) MAKE_STRING_VIEW(CharT, S)
28 
29 template <class CharT, class Allocator>
30 static void test() {
31   {
32     std::basic_string<CharT, std::char_traits<CharT>, Allocator> s(STR("testing"));
33     const std::basic_ostringstream<CharT, std::char_traits<CharT>, Allocator> ss(std::move(s));
34     assert(ss.str() == SV("testing"));
35   }
36   {
37     std::basic_string<CharT, std::char_traits<CharT>, Allocator> s(STR("testing"));
38     const std::basic_ostringstream<CharT, std::char_traits<CharT>, Allocator> ss(std::move(s), std::ios_base::binary);
39     assert(ss.str() == SV("testing"));
40   }
41 }
42 
43 int main(int, char**) {
44   test<char, std::allocator<char>>();
45   test<char, test_allocator<char>>();
46   test<char, operator_hijacker_allocator<char>>();
47 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
48   test<wchar_t, std::allocator<wchar_t>>();
49   test<wchar_t, test_allocator<wchar_t>>();
50   test<wchar_t, operator_hijacker_allocator<wchar_t>>();
51 #endif
52   return 0;
53 }
54