iterator_test.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <boost/ptr_container/ptr_vector.hpp>
  12. #include <boost/ptr_container/ptr_map.hpp>
  13. #include <boost/test/test_tools.hpp>
  14. void test_iterator()
  15. {
  16. using namespace boost;
  17. ptr_vector<int> vec;
  18. vec.push_back( new int(0) );
  19. ptr_vector<int>::iterator mutable_i = vec.begin();
  20. ptr_vector<int>::const_iterator const_i = vec.begin();
  21. BOOST_CHECK( mutable_i == const_i );
  22. BOOST_CHECK( ! (mutable_i != const_i ) );
  23. BOOST_CHECK( const_i == mutable_i );
  24. BOOST_CHECK( ! ( const_i != mutable_i ) );
  25. BOOST_CHECK( !( mutable_i < const_i ) );
  26. BOOST_CHECK( mutable_i <= const_i );
  27. BOOST_CHECK( ! ( mutable_i > const_i ) );
  28. BOOST_CHECK( mutable_i >= const_i );
  29. BOOST_CHECK( !( const_i < mutable_i ) );
  30. BOOST_CHECK( const_i <= mutable_i );
  31. BOOST_CHECK( ! ( const_i > mutable_i ) );
  32. BOOST_CHECK( const_i >= mutable_i );
  33. BOOST_CHECK( const_i - mutable_i == 0 );
  34. BOOST_CHECK( mutable_i - const_i == 0 );
  35. const ptr_vector<int>& rvec = vec;
  36. const_i = rvec.begin();
  37. ptr_map<int,int> map;
  38. int i = 0;
  39. map.insert( i, new int(0) );
  40. ptr_map<int,int>::iterator map_mutable_i = map.begin();
  41. ptr_map<int,int>::const_iterator map_const_i = map.begin();
  42. #if !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(70190006))
  43. // This only works for library implementations which conform to the
  44. // proposed resolution of the C++ Standard Library DR#179. See
  45. // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#179.
  46. BOOST_CHECK( map_mutable_i == map_const_i );
  47. BOOST_CHECK( ! ( map_mutable_i != map_const_i ) );
  48. BOOST_CHECK( map_const_i == map_mutable_i );
  49. BOOST_CHECK( ! ( map_const_i != map_mutable_i ) );
  50. #endif
  51. const ptr_map<int,int>& rmap = map;
  52. map_const_i = rmap.begin();
  53. }
  54. #include <boost/test/unit_test.hpp>
  55. using boost::unit_test::test_suite;
  56. test_suite* init_unit_test_suite( int argc, char* argv[] )
  57. {
  58. test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" );
  59. test->add( BOOST_TEST_CASE( &test_iterator ) );
  60. return test;
  61. }