Skip to content

Commit f2297c1

Browse files
kazutakahirataakadutta
authored andcommitted
[ADT] Simplify CheckedInt::from with llvm::to_underlying (NFC) (llvm#163038)
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 4f035ae commit f2297c1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/include/llvm/ADT/Sequence.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#include <type_traits> // std::is_integral, std::is_enum, std::underlying_type,
8787
// std::enable_if
8888

89+
#include "llvm/ADT/STLForwardCompat.h" // llvm::to_underlying
8990
#include "llvm/Support/MathExtras.h" // AddOverflow / SubOverflow
9091

9192
namespace llvm {
@@ -139,8 +140,7 @@ struct CheckedInt {
139140
template <typename Enum,
140141
std::enable_if_t<std::is_enum<Enum>::value, bool> = 0>
141142
static CheckedInt from(Enum FromValue) {
142-
using type = std::underlying_type_t<Enum>;
143-
return from<type>(static_cast<type>(FromValue));
143+
return from(llvm::to_underlying(FromValue));
144144
}
145145

146146
// Equality

0 commit comments

Comments
 (0)