Line data Source code
1 : 2 : 3 : #pragma once 4 : 5 : #include <array> 6 : 7 : namespace slide { 8 : 9 : template <typename T, T Nmax> 10 : class SmallVector 11 : { 12 : std::array<T, Nmax> data{}; 13 : 14 : public: 15 : T N{ 0 }; //!< number of degradation models to use (length of SEI_ID) #TODO if default should be 1 and array initialised with 0. 16 : 17 : SmallVector() = default; 18 : SmallVector(T N) : N(N) 19 : { 20 : if (N > Nmax) { 21 : std::cerr << "Array is very small! Please increase its size from settings!\n"; 22 : throw 1234; 23 : } 24 : 25 : for (T i = 0; i < N; i++) 26 : data[i] = 0; 27 : } 28 : 29 18 : inline void push_back(const T &&elem) 30 : { 31 18 : if (N > Nmax) { 32 0 : std::cerr << "Array is very small! Please increase its size from settings!\n"; 33 0 : throw 1234; 34 : } 35 : 36 18 : data[N] = elem; 37 18 : N++; 38 18 : } 39 : 40 15 : inline auto &operator[](T idx) 41 : { 42 15 : if (idx < N) 43 15 : return data[idx]; 44 : else { 45 0 : std::cerr << "Array is very small! Please increase its size from settings!\n"; 46 0 : throw 1234; 47 : } 48 : } 49 : 50 48 : inline auto empty() { return N == 0; } 51 : 52 : [[nodiscard]] inline const auto &operator[](T idx) const noexcept { return data[idx]; } 53 : 54 89118360 : [[nodiscard]] constexpr auto begin() noexcept { return data.begin(); } 55 : [[nodiscard]] constexpr auto cbegin() const noexcept { return data.cbegin(); } 56 : 57 89117894 : [[nodiscard]] constexpr auto end() { return data.begin() + N; } 58 : [[nodiscard]] constexpr auto cend() const noexcept { return data.cbegin() + N; } 59 : }; 60 : 61 : } // namespace slide