ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/dclient/include/adt/array_map.h
Revision: 1.2
Committed: Mon Oct 18 06:53:54 2010 UTC (13 years, 9 months ago) by sf-pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
Log Message:
gcc 4.5; moved some code; background colour support

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 sf-pippijn 1.2 foreach (auto const &pair, init)
14 sf-pippijn 1.1 {
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     };