1 | /* Boost.MultiIndex test for projection capabilities. |
2 | * |
3 | * Copyright 2003-2013 Joaquin M Lopez Munoz. |
4 | * Distributed under the Boost Software License, Version 1.0. |
5 | * (See accompanying file LICENSE_1_0.txt or copy at |
6 | * http://www.boost.org/LICENSE_1_0.txt) |
7 | * |
8 | * See http://www.boost.org/libs/multi_index for library home page. |
9 | */ |
10 | |
11 | #include "test_projection.hpp" |
12 | |
13 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ |
14 | #include "pre_multi_index.hpp" |
15 | #include "employee.hpp" |
16 | #include <boost/detail/lightweight_test.hpp> |
17 | |
18 | using namespace boost::multi_index; |
19 | |
20 | void test_projection() |
21 | { |
22 | employee_set es; |
23 | es.insert(x: employee(0,"Joe" ,31,1123)); |
24 | es.insert(x: employee(1,"Robert" ,27,5601)); |
25 | es.insert(x: employee(2,"John" ,40,7889)); |
26 | es.insert(x: employee(3,"Albert" ,20,9012)); |
27 | es.insert(x: employee(4,"John" ,57,1002)); |
28 | |
29 | employee_set::iterator it,itbis; |
30 | employee_set_by_name::iterator it1; |
31 | employee_set_by_age::iterator it2; |
32 | employee_set_as_inserted::iterator it3; |
33 | employee_set_by_ssn::iterator it4; |
34 | employee_set_randomly::iterator it5; |
35 | |
36 | BOOST_STATIC_ASSERT((boost::is_same< |
37 | employee_set::iterator, |
38 | nth_index_iterator<employee_set,0>::type >::value)); |
39 | BOOST_STATIC_ASSERT((boost::is_same< |
40 | employee_set_by_name::iterator, |
41 | nth_index_iterator<employee_set,1>::type >::value)); |
42 | #if defined(BOOST_NO_MEMBER_TEMPLATES) |
43 | BOOST_STATIC_ASSERT((boost::is_same< |
44 | employee_set_by_age::iterator, |
45 | index_iterator<employee_set,age>::type >::value)); |
46 | #else |
47 | BOOST_STATIC_ASSERT((boost::is_same< |
48 | employee_set_by_age::iterator, |
49 | employee_set::index_iterator<age>::type >::value)); |
50 | #endif |
51 | BOOST_STATIC_ASSERT((boost::is_same< |
52 | employee_set_as_inserted::iterator, |
53 | nth_index_iterator<employee_set,3>::type >::value)); |
54 | BOOST_STATIC_ASSERT((boost::is_same< |
55 | employee_set_by_ssn::iterator, |
56 | nth_index_iterator<employee_set,4>::type >::value)); |
57 | BOOST_STATIC_ASSERT((boost::is_same< |
58 | employee_set_randomly::iterator, |
59 | nth_index_iterator<employee_set,5>::type >::value)); |
60 | |
61 | it= es.find(x: employee(1,"Robert" ,27,5601)); |
62 | it1= project<name>(m&: es,it); |
63 | it2= project<age>(m&: es,it: it1); |
64 | it3= project<as_inserted>(m&: es,it: it2); |
65 | it4= project<ssn>(m&: es,it: it3); |
66 | it5= project<randomly>(m&: es,it: it4); |
67 | #if defined(BOOST_NO_MEMBER_TEMPLATES) |
68 | itbis=project<0>(es,it5); |
69 | #else |
70 | itbis=es.project<0>(it: it5); |
71 | #endif |
72 | |
73 | BOOST_TEST( |
74 | *it==*it1&&*it1==*it2&&*it2==*it3&&*it3==*it4&&*it4==*it5&&itbis==it); |
75 | |
76 | BOOST_TEST(project<name>(es,es.end())==get<name>(es).end()); |
77 | BOOST_TEST(project<age>(es,es.end())==get<age>(es).end()); |
78 | BOOST_TEST(project<as_inserted>(es,es.end())==get<as_inserted>(es).end()); |
79 | BOOST_TEST(project<ssn>(es,es.end())==get<ssn>(es).end()); |
80 | BOOST_TEST(project<randomly>(es,es.end())==get<randomly>(es).end()); |
81 | |
82 | const employee_set& ces=es; |
83 | |
84 | employee_set::const_iterator cit,citbis; |
85 | employee_set_by_name::const_iterator cit1; |
86 | employee_set_by_age::const_iterator cit2; |
87 | employee_set_as_inserted::const_iterator cit3; |
88 | employee_set_by_ssn::const_iterator cit4; |
89 | employee_set_randomly::const_iterator cit5; |
90 | |
91 | BOOST_STATIC_ASSERT((boost::is_same< |
92 | employee_set::const_iterator, |
93 | nth_index_const_iterator<employee_set,0>::type >::value)); |
94 | BOOST_STATIC_ASSERT((boost::is_same< |
95 | employee_set_by_name::const_iterator, |
96 | nth_index_const_iterator<employee_set,1>::type >::value)); |
97 | #if defined(BOOST_NO_MEMBER_TEMPLATES) |
98 | BOOST_STATIC_ASSERT((boost::is_same< |
99 | employee_set_by_age::const_iterator, |
100 | index_const_iterator<employee_set,age>::type >::value)); |
101 | #else |
102 | BOOST_STATIC_ASSERT((boost::is_same< |
103 | employee_set_by_age::const_iterator, |
104 | employee_set::index_const_iterator<age>::type >::value)); |
105 | #endif |
106 | BOOST_STATIC_ASSERT((boost::is_same< |
107 | employee_set_as_inserted::const_iterator, |
108 | nth_index_const_iterator<employee_set,3>::type >::value)); |
109 | BOOST_STATIC_ASSERT((boost::is_same< |
110 | employee_set_by_ssn::const_iterator, |
111 | nth_index_const_iterator<employee_set,4>::type >::value)); |
112 | BOOST_STATIC_ASSERT((boost::is_same< |
113 | employee_set_randomly::const_iterator, |
114 | nth_index_const_iterator<employee_set,5>::type >::value)); |
115 | |
116 | cit= ces.find(x: employee(4,"John" ,57,1002)); |
117 | #if defined(BOOST_NO_MEMBER_TEMPLATES) |
118 | cit1= project<by_name>(ces,cit); |
119 | #else |
120 | cit1= ces.project<by_name>(it: cit); |
121 | #endif |
122 | cit2= project<age>(m: ces,it: cit1); |
123 | #if defined(BOOST_NO_MEMBER_TEMPLATES) |
124 | cit3= project<as_inserted>(ces,cit2); |
125 | #else |
126 | cit3= ces.project<as_inserted>(it: cit2); |
127 | #endif |
128 | cit4= project<ssn>(m: ces,it: cit3); |
129 | cit5= project<randomly>(m: ces,it: cit4); |
130 | citbis=project<0>(m: ces,it: cit5); |
131 | |
132 | BOOST_TEST( |
133 | *cit==*cit1&&*cit1==*cit2&&*cit2==*cit3&&*cit3==*cit4&&*cit4==*cit5&& |
134 | citbis==cit); |
135 | } |
136 | |