| // Copyright 2005 Daniel James. |
| // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| #include <boost/functional/hash.hpp> |
| // This example illustrates how to use ndnboost::hash_combine to generate a hash |
| // value from the different members of a class. For full details see the hash |
| point(int x, int y) : x(x), y(y) {} |
| bool operator==(point const& other) const |
| return x == other.x && y == other.y; |
| friend std::size_t hash_value(point const& p) |
| ndnboost::hash_combine(seed, p.x); |
| ndnboost::hash_combine(seed, p.y); |
| ndnboost::hash<point> point_hasher; |
| assert(point_hasher(p1) == point_hasher(p4)); |
| // These tests could legally fail, but if they did it'd be a pretty bad |
| assert(point_hasher(p1) != point_hasher(p2)); |
| assert(point_hasher(p1) != point_hasher(p3)); |