]> git.stg.codes - stg.git/blob - include/stg/array.h
Replace boost::scoped_ptr with std::unique_ptr.
[stg.git] / include / stg / array.h
1 #ifndef __STG_ARRAY_H__
2 #define __STG_ARRAY_H__
3
4 #include <cstddef> // size_t
5
6 namespace STG
7 {
8
9 template <typename T, size_t S>
10 class ARRAY
11 {
12     public:
13         typedef T value_type;
14         typedef size_t size_type;
15         typedef T * iterator;
16         typedef const T * const_iterator;
17
18         ARRAY()
19         {
20             for (size_type i = 0; i < S; ++i)
21                 m_data[i] = value_type();
22         }
23
24         const value_type & operator[](size_type i) const { return m_data[i]; }
25         value_type & operator[](size_type i) { return m_data[i]; }
26         size_type size() const { return S; }
27
28         iterator begin() { return &m_data[0]; }
29         const_iterator begin() const { return &m_data[0]; }
30         iterator end() { return &m_data[S + 1]; }
31         const_iterator end() const { return &m_data[S + 1]; }
32
33         const value_type & front() const { return m_data[0]; }
34         value_type & front() { return m_data[0]; }
35         const value_type & back() const { return m_data[S]; }
36         value_type & back() { return m_data[S]; }
37
38     private:
39         value_type m_data[S];
40 };
41
42 } // namespace STG
43
44 #endif