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 | |
12 | #include "test_conv_iterators.hpp" |
13 | |
14 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ |
15 | #include "pre_multi_index.hpp" |
16 | #include "employee.hpp" |
17 | #include <boost/detail/lightweight_test.hpp> |
18 | |
19 | using namespace boost::multi_index; |
20 | |
21 | void test_conv_iterators() |
22 | { |
23 | employee_set es; |
24 | es.insert(x: employee(2,"John" ,40,7889)); |
25 | |
26 | { |
27 | const employee_set& ces=es; |
28 | employee_set::iterator it=es.find(x: employee(2,"John" ,40,7889)); |
29 | employee_set::const_iterator it1=es.find(x: employee(2,"John" ,40,7889)); |
30 | employee_set::const_iterator it2=ces.find(x: employee(2,"John" ,40,7889)); |
31 | |
32 | BOOST_TEST(it==it1&&it1==it2&&it2==it); |
33 | BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it); |
34 | } |
35 | { |
36 | employee_set_by_name& i1=get<1>(m&: es); |
37 | const employee_set_by_name& ci1=get<1>(m&: es); |
38 | employee_set_by_name::iterator it=i1.find(k: "John" ); |
39 | employee_set_by_name::const_iterator it1=i1.find(k: "John" ); |
40 | employee_set_by_name::const_iterator it2=ci1.find(k: "John" ); |
41 | |
42 | BOOST_TEST(it==it1&&it1==it2&&it2==it); |
43 | BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it); |
44 | } |
45 | { |
46 | employee_set_by_name& i1=get<1>(m&: es); |
47 | const employee_set_by_name& ci1=get<1>(m&: es); |
48 | employee_set_by_name::local_iterator it=i1.begin(n: i1.bucket(k: "John" )); |
49 | employee_set_by_name::const_local_iterator it1=i1.begin(n: i1.bucket(k: "John" )); |
50 | employee_set_by_name::const_local_iterator it2=ci1.begin(n: ci1.bucket(k: "John" )); |
51 | |
52 | BOOST_TEST(it==it1&&it1==it2&&it2==it); |
53 | BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it); |
54 | } |
55 | { |
56 | employee_set_as_inserted& i3=get<3>(m&: es); |
57 | const employee_set_as_inserted& ci3=get<3>(m&: es); |
58 | employee_set_as_inserted::iterator it=i3.begin(); |
59 | employee_set_as_inserted::const_iterator it1=i3.begin(); |
60 | employee_set_as_inserted::const_iterator it2=ci3.begin(); |
61 | |
62 | BOOST_TEST(it==it1&&it1==it2&&it2==it); |
63 | BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it); |
64 | } |
65 | { |
66 | employee_set_randomly& i5=get<5>(m&: es); |
67 | const employee_set_randomly& ci5=get<5>(m&: es); |
68 | employee_set_randomly::iterator it=i5.begin(); |
69 | employee_set_randomly::const_iterator it1=i5.begin(); |
70 | employee_set_randomly::const_iterator it2=ci5.begin(); |
71 | |
72 | BOOST_TEST(it==it1&&it1==it2&&it2==it); |
73 | BOOST_TEST(*it==*it1&&*it1==*it2&&*it2==*it); |
74 | } |
75 | } |
76 | |