1 | /* Boost.MultiIndex test for observer memfuns. |
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_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/detail/lightweight_test.hpp> |
19 | |
20 | using namespace boost::multi_index; |
21 | |
22 | void test_observers() |
23 | { |
24 | employee_set es; |
25 | const employee_set_by_name& i1=get<by_name>(m&: es); |
26 | const employee_set_by_age& i2=get<age>(m&: es); |
27 | |
28 | es.insert(x: employee(0,"Joe" ,31,1123)); |
29 | es.insert(x: employee(1,"Robert" ,27,5601)); |
30 | es.insert(x: employee(2,"John" ,40,7889)); |
31 | es.insert(x: employee(3,"Albert" ,20,9012)); |
32 | es.insert(x: 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(k: "John" ).first; |
40 | employee_set_by_name::const_iterator it1=it0;++it1; |
41 | BOOST_TEST(k(*it0)=="John" &&k(*it1)=="John" ); |
42 | BOOST_TEST(h(k(*it0))==h(k(*it1))); |
43 | BOOST_TEST(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(x: 31); |
51 | employee_set_by_age::const_iterator it1=i2.find(x: 40); |
52 | BOOST_TEST(k(*it0)==31&&k(*it1)==40); |
53 | BOOST_TEST(c(k(*it0),k(*it1))==true); |
54 | BOOST_TEST(vc(*it0,*it1)==true); |
55 | } |
56 | } |
57 | |