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_view<charT,traits> str); 15 16 #include <string_view> 17 #include <sstream> 18 #include <cassert> 19 20 #include "test_macros.h" 21 22 using std::string_view; 23 using std::wstring_view; 24 25 int main(int, char**) 26 { 27 { 28 std::ostringstream out; 29 string_view sv("some text"); 30 out << sv; 31 assert(out.good()); 32 assert(sv == out.str()); 33 } 34 { 35 std::ostringstream out; 36 std::string s("some text"); 37 string_view sv(s); 38 out.width(12); 39 out << sv; 40 assert(out.good()); 41 assert(" " + s == out.str()); 42 } 43 { 44 std::wostringstream out; 45 wstring_view sv(L"some text"); 46 out << sv; 47 assert(out.good()); 48 assert(sv == out.str()); 49 } 50 { 51 std::wostringstream out; 52 std::wstring s(L"some text"); 53 wstring_view sv(s); 54 out.width(12); 55 out << sv; 56 assert(out.good()); 57 assert(L" " + s == out.str()); 58 } 59 60 return 0; 61 } 62