Line data Source code
1 : #pragma once
2 :
3 : #include <IntegerCast.h>
4 :
5 : #include <libassert/assert.hpp>
6 :
7 : #include <array>
8 :
9 : template <typename map_to> class AsciiMap {
10 : public:
11 : using MapTo = map_to;
12 :
13 : constexpr AsciiMap(MapTo const &defaultValue) {
14 : std::fill(_map.begin(), _map.end(), defaultValue);
15 : }
16 :
17 62000 : [[nodiscard]] constexpr MapTo const &operator[](char const c) const {
18 62000 : DEBUG_ASSERT(c >= 0);
19 62000 : DEBUG_ASSERT(c < _map.size());
20 62000 : return _map[c];
21 62000 : }
22 :
23 0 : [[nodiscard]] constexpr MapTo &operator[](char const c) {
24 0 : DEBUG_ASSERT(c >= 0);
25 0 : DEBUG_ASSERT(c < _map.size());
26 0 : return _map[c];
27 0 : }
28 :
29 : private:
30 : std::array<MapTo, 128u> _map;
31 : };
|