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: c++03, c++11, c++14, c++17 |
11 | |
12 | // friend bool operator==(const iterator& x, default_sentinel_t); |
13 | |
14 | #include <cassert> |
15 | #include <ranges> |
16 | #include <sstream> |
17 | |
18 | #include "test_macros.h" |
19 | #include "../utils.h" |
20 | |
21 | template <class CharT> |
22 | void test() { |
23 | // fail to read |
24 | { |
25 | auto iss = make_string_stream<CharT>("a123 4" ); |
26 | std::ranges::basic_istream_view<int, CharT> isv{iss}; |
27 | auto it = isv.begin(); |
28 | assert(it == std::default_sentinel); |
29 | } |
30 | |
31 | // iterate through the end |
32 | { |
33 | auto iss = make_string_stream<CharT>("123 " ); |
34 | std::ranges::basic_istream_view<int, CharT> isv{iss}; |
35 | auto it = isv.begin(); |
36 | assert(it != std::default_sentinel); |
37 | ++it; |
38 | assert(it == std::default_sentinel); |
39 | } |
40 | |
41 | // empty stream |
42 | { |
43 | auto iss = make_string_stream<CharT>("" ); |
44 | std::ranges::basic_istream_view<int, CharT> isv{iss}; |
45 | auto it = isv.begin(); |
46 | assert(it == std::default_sentinel); |
47 | } |
48 | } |
49 | |
50 | int main(int, char**) { |
51 | test<char>(); |
52 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
53 | test<wchar_t>(); |
54 | #endif |
55 | |
56 | return 0; |
57 | } |
58 | |