View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

enumarray.h
Go to the documentation of this file.
1#ifndef VISTLE_ENUM_ARRAY_H
2#define VISTLE_ENUM_ARRAY_H
3#include <array>
4#include <initializer_list>
5
6namespace vistle {
7//an array with an entry of type T for each type in Enum (last type must be named LastDummy and is not included)
8template<typename T, typename Enum>
9class EnumArray {
10private:
11 typedef std::array<T, static_cast<int>(Enum::LastDummy)> ArrayType;
12 ArrayType m_array;
13
14public:
15 template<typename... Args>
16 EnumArray(Args &&...args): m_array({std::forward<Args>(args)...})
17 {}
18 inline T &operator[](Enum e) { return m_array[static_cast<int>(e)]; }
19 inline const T &operator[](Enum e) const { return m_array[static_cast<int>(e)]; }
20
21 inline typename ArrayType::iterator begin() { return m_array.begin(); }
22 inline typename ArrayType::const_iterator begin() const { return m_array.begin(); }
23 inline typename ArrayType::iterator end() { return m_array.end(); }
24 inline typename ArrayType::const_iterator end() const { return m_array.end(); }
25};
26} // namespace vistle
27
28#endif //VISTLE_ENUM_ARRAY_H
Definition: enumarray.h:9
EnumArray(Args &&...args)
Definition: enumarray.h:16
ArrayType::const_iterator begin() const
Definition: enumarray.h:22
ArrayType::iterator begin()
Definition: enumarray.h:21
ArrayType::iterator end()
Definition: enumarray.h:23
ArrayType::const_iterator end() const
Definition: enumarray.h:24
T & operator[](Enum e)
Definition: enumarray.h:18
const T & operator[](Enum e) const
Definition: enumarray.h:19
Definition: allobjects.cpp:30