]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // Copyright 2006-2009 Daniel James. | |
3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #include <boost/unordered_set.hpp> | |
7 | #include <boost/detail/lightweight_test.hpp> | |
8 | ||
9 | //[point_example1 | |
10 | struct point { | |
11 | int x; | |
12 | int y; | |
13 | }; | |
14 | ||
15 | bool operator==(point const& p1, point const& p2) | |
16 | { | |
17 | return p1.x == p2.x && p1.y == p2.y; | |
18 | } | |
19 | ||
20 | struct point_hash | |
21 | : std::unary_function<point, std::size_t> | |
22 | { | |
23 | std::size_t operator()(point const& p) const | |
24 | { | |
25 | std::size_t seed = 0; | |
26 | boost::hash_combine(seed, p.x); | |
27 | boost::hash_combine(seed, p.y); | |
28 | return seed; | |
29 | } | |
30 | }; | |
31 | ||
32 | boost::unordered_multiset<point, point_hash> points; | |
33 | //] | |
34 | ||
35 | int main() { | |
36 | point x[] = {{1,2}, {3,4}, {1,5}, {1,2}}; | |
37 | for(int i = 0; i < sizeof(x) / sizeof(point); ++i) | |
38 | points.insert(x[i]); | |
39 | BOOST_TEST(points.count(x[0]) == 2); | |
40 | BOOST_TEST(points.count(x[1]) == 1); | |
41 | point y = {10, 2}; | |
42 | BOOST_TEST(points.count(y) == 0); | |
43 | ||
44 | return boost::report_errors(); | |
45 | } |