Skip to content

Commit ec061cd

Browse files
[ADT] Simplify DenseMapInfo<std::tuple<...>> with constexpr if (NFC) (#156810)
This patch consolidates two implementations of getHashValueImpl into one with "constexpr if", which should be more readable than the SFINAE-based approach. The same applies to isEqualImpl.
1 parent a614807 commit ec061cd

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

llvm/include/llvm/ADT/DenseMapInfo.h

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -179,41 +179,35 @@ template <typename... Ts> struct DenseMapInfo<std::tuple<Ts...>> {
179179
return Tuple(DenseMapInfo<Ts>::getTombstoneKey()...);
180180
}
181181

182-
template <unsigned I>
183-
static unsigned getHashValueImpl(const Tuple &values, std::false_type) {
184-
using EltType = std::tuple_element_t<I, Tuple>;
185-
std::integral_constant<bool, I + 1 == sizeof...(Ts)> atEnd;
186-
return detail::combineHashValue(
187-
DenseMapInfo<EltType>::getHashValue(std::get<I>(values)),
188-
getHashValueImpl<I + 1>(values, atEnd));
189-
}
190-
191-
template <unsigned I>
192-
static unsigned getHashValueImpl(const Tuple &, std::true_type) {
193-
return 0;
182+
template <unsigned I> static unsigned getHashValueImpl(const Tuple &values) {
183+
if constexpr (I == sizeof...(Ts))
184+
return 0;
185+
else {
186+
using EltType = std::tuple_element_t<I, Tuple>;
187+
return detail::combineHashValue(
188+
DenseMapInfo<EltType>::getHashValue(std::get<I>(values)),
189+
getHashValueImpl<I + 1>(values));
190+
}
194191
}
195192

196193
static unsigned getHashValue(const std::tuple<Ts...> &values) {
197-
std::integral_constant<bool, 0 == sizeof...(Ts)> atEnd;
198-
return getHashValueImpl<0>(values, atEnd);
194+
return getHashValueImpl<0>(values);
199195
}
200196

201197
template <unsigned I>
202-
static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs, std::false_type) {
203-
using EltType = std::tuple_element_t<I, Tuple>;
204-
std::integral_constant<bool, I + 1 == sizeof...(Ts)> atEnd;
205-
return DenseMapInfo<EltType>::isEqual(std::get<I>(lhs), std::get<I>(rhs)) &&
206-
isEqualImpl<I + 1>(lhs, rhs, atEnd);
207-
}
208-
209-
template <unsigned I>
210-
static bool isEqualImpl(const Tuple &, const Tuple &, std::true_type) {
211-
return true;
198+
static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs) {
199+
if constexpr (I == sizeof...(Ts))
200+
return true;
201+
else {
202+
using EltType = std::tuple_element_t<I, Tuple>;
203+
return DenseMapInfo<EltType>::isEqual(std::get<I>(lhs),
204+
std::get<I>(rhs)) &&
205+
isEqualImpl<I + 1>(lhs, rhs);
206+
}
212207
}
213208

214209
static bool isEqual(const Tuple &lhs, const Tuple &rhs) {
215-
std::integral_constant<bool, 0 == sizeof...(Ts)> atEnd;
216-
return isEqualImpl<0>(lhs, rhs, atEnd);
210+
return isEqualImpl<0>(lhs, rhs);
217211
}
218212
};
219213

0 commit comments

Comments
 (0)