]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container_hash/examples/point.cpp
2 // Copyright 2005 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)
6 // Force use of assert.
11 #include <boost/container_hash/hash.hpp>
14 // This example illustrates how to use boost::hash_combine to generate a hash
15 // value from the different members of a class. For full details see the hash
23 point() : x(0), y(0) {}
24 point(int x
, int y
) : x(x
), y(y
) {}
26 bool operator==(point
const& other
) const
28 return x
== other
.x
&& y
== other
.y
;
31 friend std::size_t hash_value(point
const& p
)
34 boost::hash_combine(seed
, p
.x
);
35 boost::hash_combine(seed
, p
.y
);
43 boost::hash
<point
> point_hasher
;
50 assert(point_hasher(p1
) == point_hasher(p4
));
52 // These tests could legally fail, but if they did it'd be a pretty bad
54 assert(point_hasher(p1
) != point_hasher(p2
));
55 assert(point_hasher(p1
) != point_hasher(p3
));