[PATCH] D103900: [llvm] Add enum iteration to Sequence

Arthur O'Dwyer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 10 08:40:20 PDT 2021


Quuxplusone added inline comments.


================
Comment at: llvm/include/llvm/ADT/Sequence.h:143-149
+template <typename T, bool IsEnum = std::is_enum<T>::value>
+struct StorageType {};
+
+template <typename T> struct StorageType<T, false> { using type = T; };
+template <typename T> struct StorageType<T, true> {
+  using type = typename std::underlying_type<T>::type;
 };
----------------
`llvm::detail::StorageType` is too generic of a name to land-grab, IMHO. This can/should be an implementation detail of `iota_range_iterator` — maybe it doesn't even need to be a template parameter.
```
template<class T>
struct iota_range_iterator {
    using storage_type = typename std::conditional_t<std::is_enum<T>::value,
        type_identity<T>, std::underlying_type<T>>::type;
```
Technically, instantiating underlying_type<T> for non-enum T was UB before C++20.
In practice I'd hope it works on all implementations we care about.
I don't know where to get a C++14-friendly `type_identity` but hopefully you can figure it out.
https://en.cppreference.com/w/cpp/types/type_identity


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103900/new/

https://reviews.llvm.org/D103900



More information about the llvm-commits mailing list