ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/dclient/include/adt/array_map.h
Revision: 1.1
Committed: Sun Oct 17 08:14:44 2010 UTC (13 years, 9 months ago) by sf-pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import

File Contents

# User Rev Content
1 sf-pippijn 1.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     for (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     };