1//
2// Boost.Pointer Container
3//
4// Copyright Thorsten Ottosen 2003-2005. Use, modification and
5// distribution is subject to the Boost Software License, Version
6// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9// For more information, see http://www.boost.org/libs/ptr_container/
10//
11
12#include <boost/ptr_container/ptr_vector.hpp>
13#include <boost/ptr_container/ptr_map.hpp>
14#include <boost/test/test_tools.hpp>
15
16void test_iterator()
17{
18 using namespace boost;
19 ptr_vector<int> vec;
20 vec.push_back( x: new int(0) );
21 ptr_vector<int>::iterator mutable_i = vec.begin();
22 ptr_vector<int>::const_iterator const_i = vec.begin();
23
24 BOOST_CHECK( mutable_i == const_i );
25 BOOST_CHECK( ! (mutable_i != const_i ) );
26 BOOST_CHECK( const_i == mutable_i );
27 BOOST_CHECK( ! ( const_i != mutable_i ) );
28
29 BOOST_CHECK( !( mutable_i < const_i ) );
30 BOOST_CHECK( mutable_i <= const_i );
31 BOOST_CHECK( ! ( mutable_i > const_i ) );
32 BOOST_CHECK( mutable_i >= const_i );
33 BOOST_CHECK( !( const_i < mutable_i ) );
34 BOOST_CHECK( const_i <= mutable_i );
35 BOOST_CHECK( ! ( const_i > mutable_i ) );
36 BOOST_CHECK( const_i >= mutable_i );
37
38 BOOST_CHECK( const_i - mutable_i == 0 );
39 BOOST_CHECK( mutable_i - const_i == 0 );
40
41 const ptr_vector<int>& rvec = vec;
42 const_i = rvec.begin();
43
44 ptr_map<int,int> map;
45 int i = 0;
46 map.insert( key&: i, x: new int(0) );
47 ptr_map<int,int>::iterator map_mutable_i = map.begin();
48 ptr_map<int,int>::const_iterator map_const_i = map.begin();
49
50#if !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(70190006))
51 // This only works for library implementations which conform to the
52 // proposed resolution of the C++ Standard Library DR#179. See
53 // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#179.
54 BOOST_CHECK( map_mutable_i == map_const_i );
55 BOOST_CHECK( ! ( map_mutable_i != map_const_i ) );
56 BOOST_CHECK( map_const_i == map_mutable_i );
57 BOOST_CHECK( ! ( map_const_i != map_mutable_i ) );
58#endif
59
60 const ptr_map<int,int>& rmap = map;
61 map_const_i = rmap.begin();
62}
63
64#include <boost/test/unit_test.hpp>
65using boost::unit_test::test_suite;
66
67test_suite* init_unit_test_suite( int argc, char* argv[] )
68{
69 test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" );
70
71 test->add( BOOST_TEST_CASE( &test_iterator ) );
72
73 return test;
74}
75
76
77
78
79

source code of boost/libs/ptr_container/test/iterator_test.cpp