test_conv_iterators.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Boost.MultiIndex test for interconvertibilty between const and
  2. * non-const iterators.
  3. *
  4. * Copyright 2003-2013 Joaquin M Lopez Munoz.
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * (See accompanying file LICENSE_1_0.txt or copy at
  7. * http://www.boost.org/LICENSE_1_0.txt)
  8. *
  9. * See http://www.boost.org/libs/multi_index for library home page.
  10. */
  11. #include "test_conv_iterators.hpp"
  12. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  13. #include "pre_multi_index.hpp"
  14. #include "employee.hpp"
  15. #include <boost/detail/lightweight_test.hpp>
  16. using namespace boost::multi_index;
  17. void test_conv_iterators()
  18. {
  19. employee_set es;
  20. es.insert(employee(2,"John",40,7889));
  21. {
  22. const employee_set& ces=es;
  23. employee_set::iterator it=es.find(employee(2,"John",40,7889));
  24. employee_set::const_iterator it1=es.find(employee(2,"John",40,7889));
  25. employee_set::const_iterator it2=ces.find(employee(2,"John",40,7889));
  26. BOOST_TEST(it==it1&&it1==it2&&it2==it);
  27. BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it);
  28. }
  29. {
  30. employee_set_by_name& i1=get<1>(es);
  31. const employee_set_by_name& ci1=get<1>(es);
  32. employee_set_by_name::iterator it=i1.find("John");
  33. employee_set_by_name::const_iterator it1=i1.find("John");
  34. employee_set_by_name::const_iterator it2=ci1.find("John");
  35. BOOST_TEST(it==it1&&it1==it2&&it2==it);
  36. BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it);
  37. }
  38. {
  39. employee_set_by_name& i1=get<1>(es);
  40. const employee_set_by_name& ci1=get<1>(es);
  41. employee_set_by_name::local_iterator it=i1.begin(i1.bucket("John"));
  42. employee_set_by_name::const_local_iterator it1=i1.begin(i1.bucket("John"));
  43. employee_set_by_name::const_local_iterator it2=ci1.begin(ci1.bucket("John"));
  44. BOOST_TEST(it==it1&&it1==it2&&it2==it);
  45. BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it);
  46. }
  47. {
  48. employee_set_as_inserted& i3=get<3>(es);
  49. const employee_set_as_inserted& ci3=get<3>(es);
  50. employee_set_as_inserted::iterator it=i3.begin();
  51. employee_set_as_inserted::const_iterator it1=i3.begin();
  52. employee_set_as_inserted::const_iterator it2=ci3.begin();
  53. BOOST_TEST(it==it1&&it1==it2&&it2==it);
  54. BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it);
  55. }
  56. {
  57. employee_set_randomly& i5=get<5>(es);
  58. const employee_set_randomly& ci5=get<5>(es);
  59. employee_set_randomly::iterator it=i5.begin();
  60. employee_set_randomly::const_iterator it1=i5.begin();
  61. employee_set_randomly::const_iterator it2=ci5.begin();
  62. BOOST_TEST(it==it1&&it1==it2&&it2==it);
  63. BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it);
  64. }
  65. }