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: c++03, c++11, c++14, c++17
10 
11 // <sstream>
12 
13 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
14 // class basic_istringstream
15 
16 // basic_string_view<charT, traits> view() const noexcept;
17 
18 #include <sstream>
19 #include <cassert>
20 #include <type_traits>
21 
22 #include "make_string.h"
23 #include "test_macros.h"
24 
25 #define STR(S) MAKE_STRING(CharT, S)
26 #define SV(S) MAKE_STRING_VIEW(CharT, S)
27 
28 template <class CharT>
29 struct my_char_traits : public std::char_traits<CharT> {};
30 
31 template <class CharT>
test()32 static void test() {
33   std::basic_istringstream<CharT> ss(STR(" 123 456"));
34   static_assert(noexcept(ss.view()));
35   assert(ss.view() == SV(" 123 456"));
36   ss.str(STR(" 789"));
37   ss.clear();
38   assert(ss.view() == SV(" 789"));
39 
40   const std::basic_istringstream<CharT> css(STR("abc"));
41   static_assert(noexcept(css.view()));
42   assert(css.view() == SV("abc"));
43 
44   std::basic_istringstream<CharT, my_char_traits<CharT>> tss;
45   static_assert(std::is_same_v<decltype(tss.view()), std::basic_string_view<CharT, my_char_traits<CharT>>>);
46 }
47 
main(int,char **)48 int main(int, char**) {
49   test<char>();
50 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
51   test<wchar_t>();
52 #endif
53   return 0;
54 }
55