Skip to content

Commit f0cc50c

Browse files
[ADT] Add hash_combine_range that takes a range (NFC) (#136459)
The new function will allow us to replace: hash_combine_range(Ops.begin(), Ops.end()) with: hash_combine_range(Ops)
1 parent ea3eb8d commit f0cc50c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

llvm/include/llvm/ADT/Hashing.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#ifndef LLVM_ADT_HASHING_H
4545
#define LLVM_ADT_HASHING_H
4646

47+
#include "llvm/ADT/ADL.h"
4748
#include "llvm/Config/abi-breaking.h"
4849
#include "llvm/Support/DataTypes.h"
4950
#include "llvm/Support/ErrorHandling.h"
@@ -469,6 +470,10 @@ hash_code hash_combine_range(InputIteratorT first, InputIteratorT last) {
469470
return ::llvm::hashing::detail::hash_combine_range_impl(first, last);
470471
}
471472

473+
// A wrapper for hash_combine_range above.
474+
template <typename RangeT> hash_code hash_combine_range(RangeT &&R) {
475+
return hash_combine_range(adl_begin(R), adl_end(R));
476+
}
472477

473478
// Implementation details for hash_combine.
474479
namespace hashing {

llvm/unittests/ADT/HashingTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,19 @@ TEST(HashingTest, HashCombineRangeBasicTest) {
166166
hash_code arr1_hash = hash_combine_range(begin(arr1), end(arr1));
167167
EXPECT_NE(dummy_hash, arr1_hash);
168168
EXPECT_EQ(arr1_hash, hash_combine_range(begin(arr1), end(arr1)));
169+
EXPECT_EQ(arr1_hash, hash_combine_range(arr1));
169170

170171
const std::vector<int> vec(begin(arr1), end(arr1));
171172
EXPECT_EQ(arr1_hash, hash_combine_range(vec.begin(), vec.end()));
173+
EXPECT_EQ(arr1_hash, hash_combine_range(vec));
172174

173175
const std::list<int> list(begin(arr1), end(arr1));
174176
EXPECT_EQ(arr1_hash, hash_combine_range(list.begin(), list.end()));
177+
EXPECT_EQ(arr1_hash, hash_combine_range(list));
175178

176179
const std::deque<int> deque(begin(arr1), end(arr1));
177180
EXPECT_EQ(arr1_hash, hash_combine_range(deque.begin(), deque.end()));
181+
EXPECT_EQ(arr1_hash, hash_combine_range(deque));
178182

179183
const int arr2[] = { 3, 2, 1 };
180184
hash_code arr2_hash = hash_combine_range(begin(arr2), end(arr2));

0 commit comments

Comments
 (0)