1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #ifndef ARRAY_H
- #define ARRAY_H
- template<typename T, int N>
- class Array final {
- T data[N];
- public:
- Array() = default;
- Array(const T& t) {
- fill(t);
- }
-
- void fill(const T& t) {
- for(int i = 0; i < N; i++) {
- data[i] = t;
- }
- }
- T& operator[](int index) {
- return data[index];
- }
- const T& operator[](int index) const {
- return data[index];
- }
- T* begin() {
- return data;
- }
- T* end() {
- return data + N;
- }
- const T* begin() const {
- return data;
- }
- const T* end() const {
- return data + N;
- }
- constexpr int getLength() const {
- return N;
- }
- };
- #endif
|