Skip to content

Commit 726e3ab

Browse files
[ADT] Simplify addEnumValues with llvm::to_underlying (NFC)
llvm::to_underlying, forward ported from C++23, conveniently packages static_cast and std::underlying_type_t like so: static_cast<std::underlying_type_t<EnumTy>>(E)
1 parent 3f46a5c commit 726e3ab

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,10 @@ using TypeAtIndex = std::tuple_element_t<I, std::tuple<Ts...>>;
161161
/// Helper which adds two underlying types of enumeration type.
162162
/// Implicit conversion to a common type is accepted.
163163
template <typename EnumTy1, typename EnumTy2,
164-
typename UT1 = std::enable_if_t<std::is_enum<EnumTy1>::value,
165-
std::underlying_type_t<EnumTy1>>,
166-
typename UT2 = std::enable_if_t<std::is_enum<EnumTy2>::value,
167-
std::underlying_type_t<EnumTy2>>>
164+
typename = std::enable_if_t<std::is_enum_v<EnumTy1> &&
165+
std::is_enum_v<EnumTy2>>>
168166
constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS) {
169-
return static_cast<UT1>(LHS) + static_cast<UT2>(RHS);
167+
return llvm::to_underlying(LHS) + llvm::to_underlying(RHS);
170168
}
171169

172170
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)