-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtuple_hash.hpp
More file actions
35 lines (31 loc) · 866 Bytes
/
tuple_hash.hpp
File metadata and controls
35 lines (31 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <boost/container_hash/hash.hpp>
#include <functional>
#include <tuple>
template <class... Args>
struct std::hash<std::tuple<Args...>> {
private:
template <size_t I>
void hash_element_of_tuple(size_t &result,
const std::tuple<Args...> &v) const {
auto &item = std::get<I>(v);
boost::hash_combine(result,
std::hash<std::remove_cvref_t<decltype(item)>>()(item));
if constexpr (sizeof...(Args) > I + 1) {
hash_element_of_tuple<I + 1>(result, v);
}
}
public:
size_t operator()(const std::tuple<Args...> &value) const {
size_t result = 0;
if constexpr (sizeof...(Args) > 0) {
hash_element_of_tuple<0>(result, value);
}
return result;
}
};