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 | // class istream_iterator |
12 | |
13 | // template <class T, class charT, class traits, class Distance> |
14 | // bool operator==(const istream_iterator<T,charT,traits,Distance> &x, |
15 | // const istream_iterator<T,charT,traits,Distance> &y); |
16 | // |
17 | // template <class T, class charT, class traits, class Distance> |
18 | // bool operator!=(const istream_iterator<T,charT,traits,Distance> &x, |
19 | // const istream_iterator<T,charT,traits,Distance> &y); |
20 | // |
21 | // friend bool operator==(const istream_iterator& i, default_sentinel_t); // since C++20 |
22 | |
23 | #include <iterator> |
24 | #include <sstream> |
25 | #include <cassert> |
26 | |
27 | #include "test_macros.h" |
28 | |
29 | int main(int, char**) { |
30 | { |
31 | std::istringstream inf1(" 1 23" ); |
32 | std::istringstream inf2(" 1 23" ); |
33 | std::istream_iterator<int> i1(inf1); |
34 | std::istream_iterator<int> i2(inf1); |
35 | std::istream_iterator<int> i3(inf2); |
36 | std::istream_iterator<int> i4; |
37 | std::istream_iterator<int> i5; |
38 | assert(i1 == i1); |
39 | assert(i1 == i2); |
40 | assert(i1 != i3); |
41 | assert(i1 != i4); |
42 | assert(i1 != i5); |
43 | |
44 | assert(i2 == i2); |
45 | assert(i2 != i3); |
46 | assert(i2 != i4); |
47 | assert(i2 != i5); |
48 | |
49 | assert(i3 == i3); |
50 | assert(i3 != i4); |
51 | assert(i3 != i5); |
52 | |
53 | assert(i4 == i4); |
54 | assert(i4 == i5); |
55 | |
56 | assert(std::operator==(i1, i2)); |
57 | #if TEST_STD_VER <= 17 |
58 | assert(std::operator!=(i1, i3)); |
59 | #endif |
60 | } |
61 | |
62 | #if TEST_STD_VER > 17 |
63 | { |
64 | std::istream_iterator<int> i1; |
65 | std::istream_iterator<int> i2(std::default_sentinel); |
66 | assert(i1 == i2); |
67 | |
68 | assert(i1 == std::default_sentinel); |
69 | assert(i2 == std::default_sentinel); |
70 | assert(std::default_sentinel == i1); |
71 | assert(std::default_sentinel == i2); |
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::istream_iterator<int> i3(stream); |
79 | |
80 | assert(!(i3 == std::default_sentinel)); |
81 | assert(!(std::default_sentinel == i3)); |
82 | assert(i3 != std::default_sentinel); |
83 | assert(std::default_sentinel != i3); |
84 | } |
85 | #endif |
86 | |
87 | return 0; |
88 | } |
89 | |