Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

updated boost from 1_33_1 to 1_34_1

File size: 1.8 KB
Line 
1/* Boost.MultiIndex test for observer memfuns.
2 *
3 * Copyright 2003-2005 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_observers.hpp"
12
13#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
14#include <algorithm>
15#include <vector>
16#include "pre_multi_index.hpp"
17#include "employee.hpp"
18#include <boost/test/test_tools.hpp>
19
20using namespace boost::multi_index;
21
22void test_observers()
23{
24  employee_set                es;
25  const employee_set_by_name& i1=get<by_name>(es);
26  const employee_set_by_age&  i2=get<age>(es);
27
28  es.insert(employee(0,"Joe",31,1123));
29  es.insert(employee(1,"Robert",27,5601));
30  es.insert(employee(2,"John",40,7889));
31  es.insert(employee(3,"Albert",20,9012));
32  es.insert(employee(4,"John",57,1002));
33
34  {
35    employee_set_by_name::key_from_value k=i1.key_extractor();
36    employee_set_by_name::hasher         h=i1.hash_function();
37    employee_set_by_name::key_equal      eq=i1.key_eq();
38
39    employee_set_by_name::const_iterator it0=i1.equal_range("John").first;
40    employee_set_by_name::const_iterator it1=it0;++it1;
41    BOOST_CHECK(k(*it0)=="John"&&k(*it1)=="John");
42    BOOST_CHECK(h(k(*it0))==h(k(*it1)));
43    BOOST_CHECK(eq(k(*it0),k(*it1))==true);
44  }
45  {
46    employee_set_by_age::key_from_value k=i2.key_extractor();
47    employee_set_by_age::key_compare    c=i2.key_comp();
48    employee_set_by_age::value_compare  vc=i2.value_comp();
49
50    employee_set_by_age::const_iterator it0=i2.find(31);
51    employee_set_by_age::const_iterator it1=i2.find(40);
52    BOOST_CHECK(k(*it0)==31&&k(*it1)==40);
53    BOOST_CHECK(c(k(*it0),k(*it1))==true);
54    BOOST_CHECK(vc(*it0,*it1)==true);
55  }
56}
Note: See TracBrowser for help on using the repository browser.