diff --git a/llvm/include/llvm/ADT/EnumeratedArray.h b/llvm/include/llvm/ADT/EnumeratedArray.h --- a/llvm/include/llvm/ADT/EnumeratedArray.h +++ b/llvm/include/llvm/ADT/EnumeratedArray.h @@ -16,6 +16,7 @@ #define LLVM_ADT_ENUMERATEDARRAY_H #include +#include namespace llvm { @@ -24,12 +25,31 @@ IndexType Size = 1 + static_cast(LargestEnum)> class EnumeratedArray { public: + using value_type = ValueType; + using iterator = ValueType *; + using const_iterator = const ValueType *; + + using const_reverse_iterator = std::reverse_iterator; + using reverse_iterator = std::reverse_iterator; + + using reference = ValueType &; + using const_reference = const ValueType &; + using pointer = ValueType *; + using const_pointer = const ValueType *; + EnumeratedArray() = default; EnumeratedArray(ValueType V) { for (IndexType IX = 0; IX < Size; ++IX) { Underlying[IX] = V; } } + EnumeratedArray(std::initializer_list Init) { + assert(Init.size() == Size && "Incorrect initializer size"); + for (IndexType IX = 0; IX < Size; ++IX) { + Underlying[IX] = *(Init.begin() + IX); + } + } + inline const ValueType &operator[](const Enumeration Index) const { auto IX = static_cast(Index); assert(IX >= 0 && IX < Size && "Index is out of bounds."); @@ -40,7 +60,23 @@ static_cast &>(*this)[Index]); } - inline IndexType size() { return Size; } + inline IndexType size() const { return Size; } + inline bool empty() const { return size() == 0; } + + inline iterator begin() { return Underlying; } + inline const_iterator begin() const { return Underlying; } + + inline iterator end() { return begin() + size(); } + inline const_iterator end() const { return begin() + size(); } + + inline reverse_iterator rbegin() { return reverse_iterator(end()); } + inline const_reverse_iterator rbegin() const { + return const_reverse_iterator(end()); + } + inline const_reverse_iterator rend() const { + return const_reverse_iterator(begin()); + } + inline reverse_iterator rend() { return reverse_iterator(begin()); } private: ValueType Underlying[Size];