Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Add hash_value support for tuples. #24

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions include/llvm/ADT/Hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <cassert>
#include <cstring>
#include <string>
#include <tuple>
#include <utility>

namespace llvm {
Expand Down Expand Up @@ -656,6 +657,33 @@ hash_code hash_value(const std::basic_string<T> &arg) {
return hash_combine_range(arg.begin(), arg.end());
}

template<unsigned ...Indices>
struct UnsignedConstantIndexSet { };

template<unsigned I, unsigned N, unsigned ...Indices>
struct MakeUnsignedConstantIndexSet {
typedef typename MakeUnsignedConstantIndexSet<I+1, N, Indices..., I>::Type
Type;
};

template<unsigned N, unsigned ...Indices>
struct MakeUnsignedConstantIndexSet<N, N, Indices...> {
typedef UnsignedConstantIndexSet<Indices...> Type;
};

template <typename ...Ts, unsigned ...Indices>
hash_code hash_value_tuple_helper(const std::tuple<Ts...> &arg,
UnsignedConstantIndexSet<Indices...> indices) {
return hash_combine(hash_value(std::get<Indices>(arg))...);
}

template <typename ...Ts>
hash_code hash_value(const std::tuple<Ts...> &arg) {
return hash_value_tuple_helper(
arg,
typename MakeUnsignedConstantIndexSet<0, sizeof...(Ts)>::Type());
}

} // namespace llvm

#endif