-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray.h
More file actions
82 lines (62 loc) · 1.94 KB
/
array.h
File metadata and controls
82 lines (62 loc) · 1.94 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include "algorithm.h"
#include "cstdlib/cstdint.h"
#include "initializer_list.h"
#include <cstdlib/cstring.h>
namespace firefly::std {
template<typename T, size_t N>
class array {
T data[N];
public:
using iterator = T *;
using const_iterator = const T *;
array() = default;
array(::std::initializer_list<T> const &arr)
: data{} {
firefly::std::copy(
arr.begin(), arr.end(), data);
}
array &operator=(array const &) = default;
array &operator=(array &&) = default;
array(array const &arr) noexcept {
firefly::std::copy(
arr.begin(), arr.end(), this->begin());
}
array(array &&arr) noexcept {
firefly::std::copy(
arr.begin(), arr.end(), this->begin());
}
[[nodiscard]] iterator begin() {
return data;
}
[[nodiscard]] iterator end() {
return data + N;
}
[[nodiscard]] const_iterator begin() const {
return data;
}
[[nodiscard]] const_iterator end() const {
return data + N;
}
[[nodiscard]] T &operator[](size_t idx) noexcept {
return data[idx];
}
[[nodiscard]] T const &operator[](size_t idx) const noexcept {
return data[idx];
}
[[nodiscard]] constexpr size_t max_size() const noexcept {
return N;
}
[[nodiscard]] constexpr size_t size() const noexcept {
return N;
}
[[nodiscard]] constexpr bool operator==(array<T, N> const& other) const noexcept {
for (size_t i = 0; i < other.max_size(); i++) {
if (other[i] != (*this)[i]) {
return false;
}
}
return true;
}
};
} // namespace firefly::std