summaryrefslogtreecommitdiff
path: root/src/generic/enum.hpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-06-26 10:27:47 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-06-26 15:04:16 -0700
commit34807ca9fccc7425573256645024722571ef4442 (patch)
tree5e716b7fa2d786b15da403072bb6f41f3dfbcc65 /src/generic/enum.hpp
parentb353ae37eb6d374aec4127f1849a5dce81f812b5 (diff)
downloadtmwa-34807ca9fccc7425573256645024722571ef4442.tar.gz
tmwa-34807ca9fccc7425573256645024722571ef4442.tar.bz2
tmwa-34807ca9fccc7425573256645024722571ef4442.tar.xz
tmwa-34807ca9fccc7425573256645024722571ef4442.zip
specialize inventory/storage indices
Diffstat (limited to 'src/generic/enum.hpp')
-rw-r--r--src/generic/enum.hpp60
1 files changed, 4 insertions, 56 deletions
diff --git a/src/generic/enum.hpp b/src/generic/enum.hpp
index 5f075bc..1e83c24 100644
--- a/src/generic/enum.hpp
+++ b/src/generic/enum.hpp
@@ -29,62 +29,10 @@
# include "../compat/iter.hpp"
-template<class T, class E, E max>
-struct earray
-{
- constexpr static
- size_t size()
- {
- return static_cast<size_t>(max);
- }
-
- // no ctor/dtor and one public member variable for easy initialization
- T _data[size()];
+# include "array.hpp"
- T& operator[](E v)
- {
- auto i = static_cast<size_t>(v);
- assert (i < size());
- return _data[i];
- }
-
- const T& operator[](E v) const
- {
- auto i = static_cast<size_t>(v);
- assert (i < size());
- return _data[i];
- }
-
- T *begin()
- {
- return _data;
- }
-
- T *end()
- {
- return _data + size();
- }
-
- const T *begin() const
- {
- return _data;
- }
-
- const T *end() const
- {
- return _data + size();
- }
-
- friend bool operator == (const earray& l, const earray& r)
- {
- return std::equal(l.begin(), l.end(), r.begin());
- }
-
- friend bool operator != (const earray& l, const earray& r)
- {
- return !(l == r);
- }
-};
+template<class T, class E, E max>
+using earray = GenericArray<T, EnumIndexing<E, max>>;
template<class T, class E, E max>
class eptr
@@ -102,7 +50,7 @@ public:
{}
eptr(earray<T, E, max>& arr)
- : _data(arr._data)
+ : _data(arr.data)
{}
T& operator [](E v) const