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 // <string>
10 
11 // template<class charT, class traits, class Allocator>
12 //   basic_ostream<charT, traits>&
13 //   operator<<(basic_ostream<charT, traits>& os,
14 //              const basic_string<charT,traits,Allocator>& str);
15 
16 #include <string>
17 #include <sstream>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 
main(int,char **)23 int main(int, char**)
24 {
25     {
26         std::ostringstream out;
27         std::string s("some text");
28         out << s;
29         assert(out.good());
30         assert(s == out.str());
31     }
32     {
33         std::ostringstream out;
34         std::string s("some text");
35         out.width(12);
36         out << s;
37         assert(out.good());
38         assert("   " + s == out.str());
39     }
40     {
41         std::wostringstream out;
42         std::wstring s(L"some text");
43         out << s;
44         assert(out.good());
45         assert(s == out.str());
46     }
47     {
48         std::wostringstream out;
49         std::wstring s(L"some text");
50         out.width(12);
51         out << s;
52         assert(out.good());
53         assert(L"   " + s == out.str());
54     }
55 #if TEST_STD_VER >= 11
56     {
57         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
58         std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out;
59         S s("some text");
60         out << s;
61         assert(out.good());
62         assert(s == out.str());
63     }
64     {
65         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
66         std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out;
67         S s("some text");
68         out.width(12);
69         out << s;
70         assert(out.good());
71         assert("   " + s == out.str());
72     }
73     {
74         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
75         std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out;
76         S s(L"some text");
77         out << s;
78         assert(out.good());
79         assert(s == out.str());
80     }
81     {
82         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
83         std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out;
84         S s(L"some text");
85         out.width(12);
86         out << s;
87         assert(out.good());
88         assert(L"   " + s == out.str());
89     }
90 #endif
91 
92   return 0;
93 }
94