| 23 | |
| 24 | template <std::size_t Size, class Key, class T = std::string_view> |
| 25 | class DenseEnumMap { |
| 26 | static_assert(std::is_enum_v<Key>, "Key should be an enum type!"); |
| 27 | |
| 28 | public: |
| 29 | class ConstIterator; |
| 30 | using key_type = Key; |
| 31 | using mapped_type = T; |
| 32 | using value_type = const std::pair<Key, T>; |
| 33 | using size_type = std::size_t; |
| 34 | using difference_type = std::ptrdiff_t; |
| 35 | using reference = value_type &; |
| 36 | using const_reference = const value_type &; |
| 37 | using pointer = value_type *; |
| 38 | using const_pointer = const value_type *; |
| 39 | using iterator = ConstIterator; |
| 40 | using const_iterator = ConstIterator; |
| 41 | |
| 42 | constexpr DenseEnumMap() noexcept = delete; |
| 43 | constexpr DenseEnumMap(const DenseEnumMap &) noexcept = delete; |
| 44 | constexpr DenseEnumMap(DenseEnumMap &&) noexcept = default; |
| 45 | constexpr DenseEnumMap &operator=(const DenseEnumMap &) noexcept = delete; |
| 46 | constexpr DenseEnumMap &operator=(DenseEnumMap &&) noexcept = default; |
| 47 | |
| 48 | constexpr DenseEnumMap( |
| 49 | const std::pair<Key, std::string_view> (&Array)[Size]) noexcept { |
| 50 | for (size_type I = 0; I < Size; ++I) { |
| 51 | Data[static_cast<size_type>(Array[I].first)] = Array[I].second; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | constexpr const mapped_type &operator[](key_type K) const noexcept { |
| 56 | return Data[static_cast<size_type>(K)]; |
| 57 | } |
| 58 | |
| 59 | constexpr const_iterator begin() const noexcept { |
| 60 | return {Data, static_cast<size_type>(0)}; |
| 61 | } |
| 62 | |
| 63 | constexpr const_iterator end() const noexcept { |
| 64 | return {Data, static_cast<size_type>(Size)}; |
| 65 | } |
| 66 | |
| 67 | constexpr const_iterator find(key_type K) const noexcept { |
| 68 | return {Data, std::min(static_cast<size_type>(K), Size)}; |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | std::array<T, Size> Data; |
| 73 | }; |
| 74 | |
| 75 | template <class Key, std::size_t Size> |
| 76 | DenseEnumMap(const std::pair<Key, std::string_view> (&)[Size]) |
no outgoing calls
no test coverage detected