123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #ifndef CORE_ARRAY_HPP
- #define CORE_ARRAY_HPP
- #include "utils/ArrayString.hpp"
- namespace Core {
- template<typename T, int N>
- class Array final {
- static_assert(N > 0, "Array size must be positive");
- T data[static_cast<unsigned int>(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;
- }
- template<typename String>
- check_return Error toString(String& s) const {
- return Core::toString(s, *this);
- }
- };
- }
- #endif
|