]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/support/istream_iterator_basic.cpp
1 // Copyright (c) 2016 Jeffrey E. Trull
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // A series of simple tests for the istream_iterator
8 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/spirit/include/support_istream_iterator.hpp>
16 std::stringstream
ss("HELO\n");
17 boost::spirit::istream_iterator
it(ss
);
19 // Check iterator concepts
20 boost::spirit::istream_iterator
it2(it
); // CopyConstructible
21 BOOST_TEST( it2
== it
); // EqualityComparable
22 BOOST_TEST( *it2
== 'H' );
24 boost::spirit::istream_iterator end
; // DefaultConstructible
25 BOOST_TEST( it
!= end
);
26 it
= end
; // CopyAssignable
27 BOOST_TEST( it
== end
);
29 std::swap(it
, it2
); // Swappable
30 BOOST_TEST( it2
== end
);
31 BOOST_TEST( *it
== 'H' );
34 BOOST_TEST( *it
== 'E' );
35 BOOST_TEST( *it
++ == 'E' );
37 // "Incrementing a copy of a does not change the value read from a"
38 boost::spirit::istream_iterator it3
= it
;
39 BOOST_TEST( *it
== 'L' );
40 BOOST_TEST( *it3
== 'L' );
42 BOOST_TEST( *it
== 'O' );
43 BOOST_TEST( *it3
== 'L' );
46 // "a == b implies ++a == ++b"
47 BOOST_TEST( ++it3
== ++it
);
49 // Usage of const iterators
50 boost::spirit::istream_iterator
const itc
= it
;
51 BOOST_TEST( itc
== it
);
52 BOOST_TEST( *itc
== *it
);
54 BOOST_TEST( itc
!= it
);
56 // Skipping le/gt comparisons as unclear what they are for in forward iterators...
58 return boost::report_errors();