Squashed 'third_party/boostorg/container_hash/' content from commit 9fbda1a
Change-Id: I3db45eeb90d6b7e18fb95c2df04c0afc15541790
git-subtree-dir: third_party/boostorg/container_hash
git-subtree-split: 9fbda1a98a32498c52a1c8ebf62311bb36a44ad4
diff --git a/examples/template.hpp b/examples/template.hpp
new file mode 100644
index 0000000..0a2fe13
--- /dev/null
+++ b/examples/template.hpp
@@ -0,0 +1,36 @@
+
+// Copyright 2012 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)
+
+// This is an example of how to write a hash function for a template
+// class.
+
+#include <boost/container_hash/hash_fwd.hpp>
+
+template <typename A, typename B>
+class my_pair
+{
+ A value1;
+ B value2;
+public:
+ my_pair(A const& v1, B const& v2)
+ : value1(v1), value2(v2)
+ {}
+
+ bool operator==(my_pair const& other) const
+ {
+ return value1 == other.value1 &&
+ value2 == other.value2;
+ }
+
+ friend std::size_t hash_value(my_pair const& p)
+ {
+ std::size_t seed = 0;
+ boost::hash_combine(seed, p.value1);
+ boost::hash_combine(seed, p.value2);
+
+ return seed;
+ }
+};
+