]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/24_iterators/istream_iterator/1.cc
2f3846cd0776fc2a96ea0f4ae0226b0361ca50dc
1 // Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // C++98 24.5.1 Template class istream_iterator
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
31 using __gnu_test::test_container
;
32 using __gnu_test::output_iterator_wrapper
;
33 test_container
<int, output_iterator_wrapper
> con(arr
, arr
+N
);
34 output_iterator_wrapper
<int> out
= con
.begin();
36 istringstream
ss("1 2 3 4 5");
37 std::istream_iterator
<int> iter(ss
), end
;
40 VERIFY( iter
== end
);
41 for (int i
= 0; i
< N
; ++i
)
42 VERIFY( arr
[i
] == (i
+ 1) % N
);
44 std::istream_iterator
<int> iter2(ss
);
45 VERIFY( iter2
== end
);
49 VERIFY( iter
== end
);
51 #ifndef _GLIBCXX_DEBUG
52 // This is undefined, so aborts under debug mode.
53 // Without debug mode, it should not extract anything from the stream,
54 // and the iterator should remain at end-of-stream.
56 VERIFY( iter
== end
);
59 std::istream_iterator
<int> iter3(ss
);
60 VERIFY( iter3
!= end
);
61 VERIFY( iter3
!= iter
);
62 VERIFY( *iter3
== -1 );
64 VERIFY( *iter3
== -2 );
67 VERIFY( *iter2
== -2 );
69 VERIFY( *iter2
== -3 );
71 VERIFY( iter2
== end
);