1053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 2053d81ceSMarshall Clow // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6053d81ceSMarshall Clow // 7053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 8053d81ceSMarshall Clow 9053d81ceSMarshall Clow // <string> 10053d81ceSMarshall Clow 11053d81ceSMarshall Clow // template<class charT, class traits, class Allocator> 12053d81ceSMarshall Clow // basic_ostream<charT, traits>& 13053d81ceSMarshall Clow // operator<<(basic_ostream<charT, traits>& os, 14053d81ceSMarshall Clow // const basic_string_view<charT,traits> str); 15053d81ceSMarshall Clow 16053d81ceSMarshall Clow #include <string_view> 17053d81ceSMarshall Clow #include <sstream> 18053d81ceSMarshall Clow #include <cassert> 19053d81ceSMarshall Clow 20053d81ceSMarshall Clow using std::string_view; 21053d81ceSMarshall Clow using std::wstring_view; 22053d81ceSMarshall Clow 23*2df59c50SJF Bastien int main(int, char**) 24053d81ceSMarshall Clow { 25053d81ceSMarshall Clow { 26053d81ceSMarshall Clow std::ostringstream out; 27053d81ceSMarshall Clow string_view sv("some text"); 28053d81ceSMarshall Clow out << sv; 29053d81ceSMarshall Clow assert(out.good()); 30053d81ceSMarshall Clow assert(sv == out.str()); 31053d81ceSMarshall Clow } 32053d81ceSMarshall Clow { 33053d81ceSMarshall Clow std::ostringstream out; 34053d81ceSMarshall Clow std::string s("some text"); 35053d81ceSMarshall Clow string_view sv(s); 36053d81ceSMarshall Clow out.width(12); 37053d81ceSMarshall Clow out << sv; 38053d81ceSMarshall Clow assert(out.good()); 39053d81ceSMarshall Clow assert(" " + s == out.str()); 40053d81ceSMarshall Clow } 41053d81ceSMarshall Clow { 42053d81ceSMarshall Clow std::wostringstream out; 43053d81ceSMarshall Clow wstring_view sv(L"some text"); 44053d81ceSMarshall Clow out << sv; 45053d81ceSMarshall Clow assert(out.good()); 46053d81ceSMarshall Clow assert(sv == out.str()); 47053d81ceSMarshall Clow } 48053d81ceSMarshall Clow { 49053d81ceSMarshall Clow std::wostringstream out; 50053d81ceSMarshall Clow std::wstring s(L"some text"); 51053d81ceSMarshall Clow wstring_view sv(s); 52053d81ceSMarshall Clow out.width(12); 53053d81ceSMarshall Clow out << sv; 54053d81ceSMarshall Clow assert(out.good()); 55053d81ceSMarshall Clow assert(L" " + s == out.str()); 56053d81ceSMarshall Clow } 57*2df59c50SJF Bastien 58*2df59c50SJF Bastien return 0; 59053d81ceSMarshall Clow } 60