CppELib 1.7.0
Loading...
Searching...
No Matches
Array.h
Go to the documentation of this file.
1#ifndef CONTAINER_ARRAY_H_INCLUDED
2#define CONTAINER_ARRAY_H_INCLUDED
3
4#include <cstddef>
5#ifndef CPPELIB_NO_STD_ITERATOR
6#include <iterator>
7#endif
9
10namespace Container {
11
17template <typename T, std::size_t Size>
18struct Array {
19 typedef T value_type;
20 typedef std::size_t size_type;
21 typedef std::ptrdiff_t difference_type;
23 typedef const value_type* const_iterator;
27 typedef const value_type* const_pointer;
28#ifndef CPPELIB_NO_STD_ITERATOR
29 typedef std::reverse_iterator<iterator> reverse_iterator;
30 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
31#endif
32
34 T m_buf[Size];
36
38 {
39 return Size;
40 }
41
43 {
44 return size();
45 }
46
47 bool empty() const
48 {
49 return size() == 0; // cppcheck-suppress knownConditionTrueFalse
50 }
51
53 {
54 return *(begin() + idx);
55 }
56
58 {
59 return *(begin() + idx);
60 }
61
63 {
64 if (idx >= size()) {
66 }
67 return *(begin() + idx);
68 }
69
71 {
72 if (idx >= size()) {
74 }
75 return *(begin() + idx);
76 }
77
79 {
80 return begin();
81 }
82
84 {
85 return begin();
86 }
87
89 {
90 return &m_buf[0];
91 }
92
94 {
95 return &m_buf[0];
96 }
97
99 {
100 return &m_buf[size()];
101 }
102
104 {
105 return &m_buf[size()];
106 }
107
108#ifndef CPPELIB_NO_STD_ITERATOR
110 {
111 return reverse_iterator(end());
112 }
113
115 {
116 return const_reverse_iterator(end());
117 }
118
120 {
121 return reverse_iterator(begin());
122 }
123
125 {
127 }
128#endif
129
131 {
132 return *begin();
133 }
134
136 {
137 return *begin();
138 }
139
141 {
142 return *(end() - 1);
143 }
144
146 {
147 return *(end() - 1);
148 }
149
150 void fill(const T& data)
151 {
152 for (iterator i = begin(); i < end(); ++i) {
153 *i = data;
154 }
155 }
156
157};
158
159template <typename T, std::size_t Size>
161{
162 for (std::size_t i = 0U; i < Size; ++i) {
163 if (!(x[i] == y[i])) {
164 return false;
165 }
166 }
167 return true;
168}
169
170template <typename T, std::size_t Size>
172{
173 return !(x == y);
174}
175
176}
177
178#endif // CONTAINER_ARRAY_H_INCLUDED
Definition ContainerException.h:23
Definition Array.h:10
bool operator==(const Array< T, Size > &x, const Array< T, Size > &y)
Definition Array.h:160
bool operator!=(const Array< T, Size > &x, const Array< T, Size > &y)
Definition Array.h:171
Similar as std::array of C++11.
Definition Array.h:18
size_type size() const
Definition Array.h:37
std::size_t size_type
Definition Array.h:20
value_type * pointer
Definition Array.h:26
const_pointer data() const
Definition Array.h:83
bool empty() const
Definition Array.h:47
reference back()
Definition Array.h:140
iterator end()
Definition Array.h:98
size_type max_size() const
Definition Array.h:42
reference operator[](size_type idx)
Definition Array.h:52
const value_type * const_iterator
Definition Array.h:23
reverse_iterator rend()
Definition Array.h:119
const_iterator begin() const
Definition Array.h:93
void fill(const T &data)
Definition Array.h:150
reference front()
Definition Array.h:130
const_reference back() const
Definition Array.h:145
std::ptrdiff_t difference_type
Definition Array.h:21
T value_type
Definition Array.h:19
pointer data()
Definition Array.h:78
reverse_iterator rbegin()
Definition Array.h:109
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition Array.h:30
const_iterator end() const
Definition Array.h:103
value_type * iterator
Definition Array.h:22
const_reference front() const
Definition Array.h:135
const_reverse_iterator rend() const
Definition Array.h:124
const_reverse_iterator rbegin() const
Definition Array.h:114
value_type & reference
Definition Array.h:24
std::reverse_iterator< iterator > reverse_iterator
Definition Array.h:29
const_reference operator[](size_type idx) const
Definition Array.h:57
const value_type * const_pointer
Definition Array.h:27
reference at(size_type idx)
Definition Array.h:62
iterator begin()
Definition Array.h:88
const value_type & const_reference
Definition Array.h:25
const_reference at(size_type idx) const
Definition Array.h:70