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 // UNSUPPORTED: no-localization
10 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
11 
12 // <string_view>
13 
14 // template<class charT, class traits, class Allocator>
15 //   basic_ostream<charT, traits>&
16 //   operator<<(basic_ostream<charT, traits>& os,
17 //              const basic_string_view<charT,traits> str);
18 
19 #include <string_view>
20 #include <sstream>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 
main(int,char **)25 int main(int, char**)
26 {
27     {
28         std::ostringstream out;
29         std::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         std::string_view sv(s);
38         out.width(12);
39         out << sv;
40         assert(out.good());
41         assert("   " + s == out.str());
42     }
43 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
44     {
45         std::wostringstream out;
46         std::wstring_view sv(L"some text");
47         out << sv;
48         assert(out.good());
49         assert(sv == out.str());
50     }
51     {
52         std::wostringstream out;
53         std::wstring s(L"some text");
54         std::wstring_view sv(s);
55         out.width(12);
56         out << sv;
57         assert(out.good());
58         assert(L"   " + s == out.str());
59     }
60 #endif
61 
62   return 0;
63 }
64