-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.hpp
51 lines (40 loc) · 961 Bytes
/
array.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __ARRAY_HPP
#define __ARRAY_HPP
template <class T, size_t N>
struct array {
T data[N];
static size_t length() {
return N;
}
using type = T;
T &operator[](size_t index) {
return data[index];
}
const T &operator[](size_t index) const {
return data[index];
}
T *begin() {
return &data[0];
}
const T *begin() const {
return &data[0];
}
T *end() {
return &data[N];
}
const T *end() const {
return &data[N];
}
bool operator==(const array<T, N> &rhs) const {
if (this == &rhs)
return true;
for (size_t i = 0; i < N; i++)
if ((*this)[i] != rhs[i])
return false;
return true;
}
bool operator!=(const array<T, N> &rhs) const {
return !(*this == rhs);
}
};
#endif //__ARRAY_HPP