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/core/lightweight_test.hpp>
8
9 //[point_example1
10 struct point {
11 int x;
12 int y;
13 };
14
operator ==(point const & p1,point const & p2)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 {
operator ()point_hash22 std::size_t operator()(point const& p) const
23 {
24 std::size_t seed = 0;
25 boost::hash_combine(seed, p.x);
26 boost::hash_combine(seed, p.y);
27 return seed;
28 }
29 };
30
31 boost::unordered_multiset<point, point_hash> points;
32 //]
33
main()34 int main() {
35 point x[] = {{1,2}, {3,4}, {1,5}, {1,2}};
36 for(int i = 0; i < sizeof(x) / sizeof(point); ++i)
37 points.insert(x[i]);
38 BOOST_TEST(points.count(x[0]) == 2);
39 BOOST_TEST(points.count(x[1]) == 1);
40 point y = {10, 2};
41 BOOST_TEST(points.count(y) == 0);
42
43 return boost::report_errors();
44 }
45