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 | // <iterator> |
10 | |
11 | // istreambuf_iterator |
12 | |
13 | // template <class charT, class traits> |
14 | // bool operator==(const istreambuf_iterator<charT,traits>& a, |
15 | // const istreambuf_iterator<charT,traits>& b); |
16 | // |
17 | // friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s); // since C++20 |
18 | |
19 | #include <iterator> |
20 | #include <sstream> |
21 | #include <cassert> |
22 | |
23 | #include "test_macros.h" |
24 | |
25 | int main(int, char**) { |
26 | { |
27 | std::istringstream inf1("abc" ); |
28 | std::istringstream inf2("def" ); |
29 | std::istreambuf_iterator<char> i1(inf1); |
30 | std::istreambuf_iterator<char> i2(inf2); |
31 | std::istreambuf_iterator<char> i3; |
32 | std::istreambuf_iterator<char> i4; |
33 | std::istreambuf_iterator<char> i5(nullptr); |
34 | |
35 | assert( (i1 == i1)); |
36 | assert( (i1 == i2)); |
37 | assert(!(i1 == i3)); |
38 | assert(!(i1 == i4)); |
39 | assert(!(i1 == i5)); |
40 | |
41 | assert( (i2 == i1)); |
42 | assert( (i2 == i2)); |
43 | assert(!(i2 == i3)); |
44 | assert(!(i2 == i4)); |
45 | assert(!(i2 == i5)); |
46 | |
47 | assert(!(i3 == i1)); |
48 | assert(!(i3 == i2)); |
49 | assert( (i3 == i3)); |
50 | assert( (i3 == i4)); |
51 | assert( (i3 == i5)); |
52 | |
53 | assert(!(i4 == i1)); |
54 | assert(!(i4 == i2)); |
55 | assert( (i4 == i3)); |
56 | assert( (i4 == i4)); |
57 | assert( (i4 == i5)); |
58 | |
59 | assert(!(i5 == i1)); |
60 | assert(!(i5 == i2)); |
61 | assert( (i5 == i3)); |
62 | assert( (i5 == i4)); |
63 | assert( (i5 == i5)); |
64 | } |
65 | |
66 | #if TEST_STD_VER > 17 |
67 | { |
68 | std::istreambuf_iterator<char> i1; |
69 | std::istreambuf_iterator<char> i2(std::default_sentinel); |
70 | assert(i1 == i2); |
71 | |
72 | assert(i1 == std::default_sentinel); |
73 | assert(i2 == std::default_sentinel); |
74 | assert(std::default_sentinel == i1); |
75 | assert(std::default_sentinel == i2); |
76 | |
77 | std::istringstream stream(" 1 23" ); |
78 | std::istreambuf_iterator<char> i3(stream); |
79 | |
80 | assert(!(i3 == std::default_sentinel)); |
81 | assert(!(std::default_sentinel == i3)); |
82 | } |
83 | #endif |
84 | |
85 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
86 | { |
87 | std::wistringstream inf1(L"abc" ); |
88 | std::wistringstream inf2(L"def" ); |
89 | std::istreambuf_iterator<wchar_t> i1(inf1); |
90 | std::istreambuf_iterator<wchar_t> i2(inf2); |
91 | std::istreambuf_iterator<wchar_t> i3; |
92 | std::istreambuf_iterator<wchar_t> i4; |
93 | std::istreambuf_iterator<wchar_t> i5(nullptr); |
94 | |
95 | assert( (i1 == i1)); |
96 | assert( (i1 == i2)); |
97 | assert(!(i1 == i3)); |
98 | assert(!(i1 == i4)); |
99 | assert(!(i1 == i5)); |
100 | |
101 | assert( (i2 == i1)); |
102 | assert( (i2 == i2)); |
103 | assert(!(i2 == i3)); |
104 | assert(!(i2 == i4)); |
105 | assert(!(i2 == i5)); |
106 | |
107 | assert(!(i3 == i1)); |
108 | assert(!(i3 == i2)); |
109 | assert( (i3 == i3)); |
110 | assert( (i3 == i4)); |
111 | assert( (i3 == i5)); |
112 | |
113 | assert(!(i4 == i1)); |
114 | assert(!(i4 == i2)); |
115 | assert( (i4 == i3)); |
116 | assert( (i4 == i4)); |
117 | assert( (i4 == i5)); |
118 | |
119 | assert(!(i5 == i1)); |
120 | assert(!(i5 == i2)); |
121 | assert( (i5 == i3)); |
122 | assert( (i5 == i4)); |
123 | assert( (i5 == i5)); |
124 | } |
125 | #endif // TEST_HAS_NO_WIDE_CHARACTERS |
126 | |
127 | return 0; |
128 | } |
129 | |