Ticket #8129: ex.13.7.cpp

File ex.13.7.cpp, 1.1 KB (added by mbradle@…, 10 years ago)

test cpp file

Line 
1#include <boost/multi_index_container.hpp>
2#include <boost/multi_index/hashed_index.hpp>
3#include <boost/multi_index/member.hpp>
4#include <boost/version.hpp>
5#include <iostream>
6#include <string>
7
8struct person
9{
10 std::string name;
11 int age;
12
13 person(const std::string &n, int a) : name(n), age(a) {}
14};
15
16typedef boost::multi_index::multi_index_container<
17 person,
18 boost::multi_index::indexed_by<
19 boost::multi_index::hashed_non_unique<
20 boost::multi_index::member<
21 person, std::string, &person::name
22 >
23 >,
24 boost::multi_index::hashed_non_unique<
25 boost::multi_index::member<
26 person, int, &person::age
27 >
28 >
29 >
30> person_multi;
31
32void set_age(person &p)
33{
34 p.age = 32;
35}
36
37int main()
38{
39 person_multi persons;
40
41 persons.insert(person("Boris", 31));
42 persons.insert(person("Anton", 35));
43 persons.insert(person("Caesar", 25));
44
45 std::cout << BOOST_VERSION << std::endl;
46
47 person_multi::iterator it = persons.find("Boris");
48 persons.modify(it, set_age);
49
50 const person_multi::nth_index<1>::type &age_index = persons.get<1>();
51 std::cout << age_index.count(32) << std::endl;
52}