aboutsummaryrefslogtreecommitdiff
path: root/butl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-04-20 14:19:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-04-20 14:19:07 +0200
commit079e167e7c62c857e271bda0588064dc4030e337 (patch)
tree9c0a06ed4a00cb3ae5addf199bdb74d38af687a2 /butl
parentd29314608fe083be54f5ba8c86b0c22cf1814f3d (diff)
Add combine_hash() utility
Diffstat (limited to 'butl')
-rw-r--r--butl/utility18
1 files changed, 18 insertions, 0 deletions
diff --git a/butl/utility b/butl/utility
index 1cc45ef..efbb13b 100644
--- a/butl/utility
+++ b/butl/utility
@@ -5,6 +5,7 @@
#ifndef BUTL_UTILITY
#define BUTL_UTILITY
+#include <cstddef> // std::size_t
#include <utility> // forward()
#include <cstring> // strcmp
@@ -26,6 +27,23 @@ namespace butl
bool operator() (const P& x, const P& y) const {return *x < *y;}
};
+ // Combine one or more hash values.
+ //
+ inline std::size_t
+ combine_hash (std::size_t s, std::size_t h)
+ {
+ // Magic formula from boost::hash_combine().
+ //
+ return s ^ (h + 0x9e3779b9 + (s << 6) + (s >> 2));
+ }
+
+ template <typename... S>
+ inline std::size_t
+ combine_hash (std::size_t s, std::size_t h, S... hs)
+ {
+ return combine_hash (combine_hash (s, h), hs...);
+ }
+
// Support for reverse iteration using range-based for-loop:
//
// for (... : reverse_iterate (x)) ...