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

Commit c1dc67a

Browse files
authored
Merge pull request #25 from DougGregor/tuple-hashing-3_1
Add hash_value support for tuples.
2 parents 05ef8e5 + c02eeae commit c1dc67a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

include/llvm/ADT/Hashing.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <cassert>
5454
#include <cstring>
5555
#include <string>
56+
#include <tuple>
5657
#include <utility>
5758

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

660+
template<unsigned ...Indices>
661+
struct UnsignedConstantIndexSet { };
662+
663+
template<unsigned I, unsigned N, unsigned ...Indices>
664+
struct MakeUnsignedConstantIndexSet {
665+
typedef typename MakeUnsignedConstantIndexSet<I+1, N, Indices..., I>::Type
666+
Type;
667+
};
668+
669+
template<unsigned N, unsigned ...Indices>
670+
struct MakeUnsignedConstantIndexSet<N, N, Indices...> {
671+
typedef UnsignedConstantIndexSet<Indices...> Type;
672+
};
673+
674+
template <typename ...Ts, unsigned ...Indices>
675+
hash_code hash_value_tuple_helper(const std::tuple<Ts...> &arg,
676+
UnsignedConstantIndexSet<Indices...> indices) {
677+
return hash_combine(hash_value(std::get<Indices>(arg))...);
678+
}
679+
680+
template <typename ...Ts>
681+
hash_code hash_value(const std::tuple<Ts...> &arg) {
682+
return hash_value_tuple_helper(
683+
arg,
684+
typename MakeUnsignedConstantIndexSet<0, sizeof...(Ts)>::Type());
685+
}
686+
659687
} // namespace llvm
660688

661689
#endif

0 commit comments

Comments
 (0)