1 |
#pragma once |
2 |
|
3 |
#include <vector> |
4 |
#include <utility> |
5 |
|
6 |
template<typename T> |
7 |
struct array_map |
8 |
{ |
9 |
typedef unsigned char size_type; |
10 |
|
11 |
array_map (std::initializer_list<std::pair<size_type, T>> init) |
12 |
{ |
13 |
foreach (auto const &pair, init) |
14 |
{ |
15 |
if (pair.first >= data.size ()) |
16 |
data.resize (pair.first + 1); |
17 |
data.at (pair.first) = pair.second; |
18 |
} |
19 |
} |
20 |
|
21 |
bool has (size_type n) const { return data.size () > n && data[n]; } |
22 |
|
23 |
T &operator [] (size_type n) { return data.at (n); } |
24 |
T const &operator [] (size_type n) const { return data.at (n); } |
25 |
|
26 |
private: |
27 |
std::vector<T> data; |
28 |
}; |