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