1*0b8c8bc8SPiotr Fusik //===----------------------------------------------------------------------===//
2*0b8c8bc8SPiotr Fusik //
3*0b8c8bc8SPiotr Fusik // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b8c8bc8SPiotr Fusik // See https://llvm.org/LICENSE.txt for license information.
5*0b8c8bc8SPiotr Fusik // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b8c8bc8SPiotr Fusik //
7*0b8c8bc8SPiotr Fusik //===----------------------------------------------------------------------===//
8*0b8c8bc8SPiotr Fusik 
9*0b8c8bc8SPiotr Fusik // UNSUPPORTED: c++03, c++11, c++14, c++17
10*0b8c8bc8SPiotr Fusik 
11*0b8c8bc8SPiotr Fusik // <sstream>
12*0b8c8bc8SPiotr Fusik 
13*0b8c8bc8SPiotr Fusik // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
14*0b8c8bc8SPiotr Fusik // class basic_stringstream
15*0b8c8bc8SPiotr Fusik 
16*0b8c8bc8SPiotr Fusik // basic_string_view<charT, traits> view() const noexcept;
17*0b8c8bc8SPiotr Fusik 
18*0b8c8bc8SPiotr Fusik #include <sstream>
19*0b8c8bc8SPiotr Fusik #include <cassert>
20*0b8c8bc8SPiotr Fusik #include <type_traits>
21*0b8c8bc8SPiotr Fusik 
22*0b8c8bc8SPiotr Fusik #include "make_string.h"
23*0b8c8bc8SPiotr Fusik #include "test_macros.h"
24*0b8c8bc8SPiotr Fusik 
25*0b8c8bc8SPiotr Fusik #define STR(S) MAKE_STRING(CharT, S)
26*0b8c8bc8SPiotr Fusik #define SV(S) MAKE_STRING_VIEW(CharT, S)
27*0b8c8bc8SPiotr Fusik 
28*0b8c8bc8SPiotr Fusik template <class CharT>
29*0b8c8bc8SPiotr Fusik struct my_char_traits : public std::char_traits<CharT> {};
30*0b8c8bc8SPiotr Fusik 
31*0b8c8bc8SPiotr Fusik template <class CharT>
test()32*0b8c8bc8SPiotr Fusik static void test() {
33*0b8c8bc8SPiotr Fusik   std::basic_stringstream<CharT> ss(STR(" 123 456 "));
34*0b8c8bc8SPiotr Fusik   static_assert(noexcept(ss.view()));
35*0b8c8bc8SPiotr Fusik   assert(ss.view() == SV(" 123 456 "));
36*0b8c8bc8SPiotr Fusik   int i = 0;
37*0b8c8bc8SPiotr Fusik   ss >> i;
38*0b8c8bc8SPiotr Fusik   assert(i == 123);
39*0b8c8bc8SPiotr Fusik   ss >> i;
40*0b8c8bc8SPiotr Fusik   assert(i == 456);
41*0b8c8bc8SPiotr Fusik   ss << i << ' ' << 123;
42*0b8c8bc8SPiotr Fusik   assert(ss.view() == SV("456 1236 "));
43*0b8c8bc8SPiotr Fusik   ss.str(STR("5466 89 "));
44*0b8c8bc8SPiotr Fusik   ss >> i;
45*0b8c8bc8SPiotr Fusik   assert(i == 5466);
46*0b8c8bc8SPiotr Fusik   ss >> i;
47*0b8c8bc8SPiotr Fusik   assert(i == 89);
48*0b8c8bc8SPiotr Fusik   ss << i << ' ' << 321;
49*0b8c8bc8SPiotr Fusik   assert(ss.view() == SV("89 3219 "));
50*0b8c8bc8SPiotr Fusik 
51*0b8c8bc8SPiotr Fusik   const std::basic_stringstream<CharT> css(STR("abc"));
52*0b8c8bc8SPiotr Fusik   static_assert(noexcept(css.view()));
53*0b8c8bc8SPiotr Fusik   assert(css.view() == SV("abc"));
54*0b8c8bc8SPiotr Fusik 
55*0b8c8bc8SPiotr Fusik   std::basic_stringstream<CharT, my_char_traits<CharT>> tss;
56*0b8c8bc8SPiotr Fusik   static_assert(std::is_same_v<decltype(tss.view()), std::basic_string_view<CharT, my_char_traits<CharT>>>);
57*0b8c8bc8SPiotr Fusik }
58*0b8c8bc8SPiotr Fusik 
main(int,char **)59*0b8c8bc8SPiotr Fusik int main(int, char**) {
60*0b8c8bc8SPiotr Fusik   test<char>();
61*0b8c8bc8SPiotr Fusik #ifndef TEST_HAS_NO_WIDE_CHARACTERS
62*0b8c8bc8SPiotr Fusik   test<wchar_t>();
63*0b8c8bc8SPiotr Fusik #endif
64*0b8c8bc8SPiotr Fusik   std::stringstream ss;
65*0b8c8bc8SPiotr Fusik   ss.write("\xd1", 1);
66*0b8c8bc8SPiotr Fusik   assert(ss.view().length() == 1);
67*0b8c8bc8SPiotr Fusik   return 0;
68*0b8c8bc8SPiotr Fusik }
69