Debian Codegraph @

libcxx/test/std/strings/string.view/string.view.io/stream_insert.pass.cpp

raw
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
25 int main(int, char**) {
26 {
27 std::ostringstream out;
28 std::string_view sv("some text");
29 out << sv;
30 assert(out.good());
31 assert(sv == out.str());
32 }
33 {
34 std::ostringstream out;
35 std::string s("some text");
36 std::string_view sv(s);
37 out.width(12);
38 out << sv;
39 assert(out.good());
40 assert(" " + s == out.str());
41 }
42 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
43 {
44 std::wostringstream out;
45 std::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 std::wstring_view sv(s);
54 out.width(12);
55 out << sv;
56 assert(out.good());
57 assert(L" " + s == out.str());
58 }
59 #endif
60
61 return 0;
62 }