Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/multi_index/test/test_projection.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.6 KB
Line 
1/* Boost.MultiIndex test for projection capabilities.
2 *
3 * Copyright 2003-2006 Joaquín M López Muñoz.
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/test/test_tools.hpp>
17
18using namespace boost::multi_index;
19
20void test_projection()
21{
22  employee_set          es;
23  es.insert(employee(0,"Joe",31,1123));
24  es.insert(employee(1,"Robert",27,5601));
25  es.insert(employee(2,"John",40,7889));
26  es.insert(employee(3,"Albert",20,9012));
27  es.insert(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(employee(1,"Robert",27,5601));
62  it1=  project<name>(es,it);
63  it2=  project<age>(es,it1);
64  it3=  project<as_inserted>(es,it2);
65  it4=  project<ssn>(es,it3);
66  it5=  project<randomly>(es,it4);
67#if defined(BOOST_NO_MEMBER_TEMPLATES)
68  itbis=project<0>(es,it5);
69#else
70  itbis=es.project<0>(it5);
71#endif
72
73  BOOST_CHECK(
74    *it==*it1&&*it1==*it2&&*it2==*it3&&*it3==*it4&&*it4==*it5&&itbis==it);
75
76  BOOST_CHECK(project<name>(es,es.end())==get<name>(es).end());
77  BOOST_CHECK(project<age>(es,es.end())==get<age>(es).end());
78  BOOST_CHECK(project<as_inserted>(es,es.end())==get<as_inserted>(es).end());
79  BOOST_CHECK(project<ssn>(es,es.end())==get<ssn>(es).end());
80  BOOST_CHECK(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(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>(cit);
121#endif
122  cit2=  project<age>(ces,cit1);
123#if defined(BOOST_NO_MEMBER_TEMPLATES)
124  cit3=  project<as_inserted>(ces,cit2);
125#else
126  cit3=  ces.project<as_inserted>(cit2);
127#endif
128  cit4=  project<ssn>(ces,cit3);
129  cit5=  project<randomly>(ces,cit4);
130  citbis=project<0>(ces,cit5);
131
132  BOOST_CHECK(
133    *cit==*cit1&&*cit1==*cit2&&*cit2==*cit3&&*cit3==*cit4&&*cit4==*cit5&&
134    citbis==cit);
135}
Note: See TracBrowser for help on using the repository browser.