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 23 int main(int, char**) { 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 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 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 #endif 56 #if TEST_STD_VER >= 11 57 { 58 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 59 std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out; 60 S s("some text"); 61 out << s; 62 assert(out.good()); 63 assert(s == out.str()); 64 } 65 { 66 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 67 std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out; 68 S s("some text"); 69 out.width(12); 70 out << s; 71 assert(out.good()); 72 assert(" " + s == out.str()); 73 } 74 # ifndef TEST_HAS_NO_WIDE_CHARACTERS 75 { 76 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S; 77 std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out; 78 S s(L"some text"); 79 out << s; 80 assert(out.good()); 81 assert(s == out.str()); 82 } 83 { 84 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S; 85 std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out; 86 S s(L"some text"); 87 out.width(12); 88 out << s; 89 assert(out.good()); 90 assert(L" " + s == out.str()); 91 } 92 # endif // TEST_HAS_NO_WIDE_CHARACTERS 93 #endif // TEST_STD_VER >= 11 94 95 return 0; 96 } 97