14#include <lagrange/utils/assert.h>
18#include <initializer_list>
34template <
typename T,
size_t N>
38 std::array<T, N> m_array;
48 auto it = init.begin();
49 for (
size_t i = 0; i < m_size; ++i) {
50 m_array[i] = std::move(*it);
55 bool empty()
const {
return m_size == 0; }
57 size_t size()
const {
return m_size; }
59 void clear() { m_size = 0; }
61 void resize(
const size_t i)
67 void push_back(
const T& v)
70 m_array[m_size++] = v;
73 template <
class...
Args>
74 void emplace_back(
Args&&... args)
77 m_array[m_size++] = T(std::forward<Args>(args)...);
86 T* data() {
return m_array.data(); }
88 const T* data()
const {
return m_array.data(); }
93 return m_array.front();
96 const T& front()
const
99 return m_array.front();
105 return m_array.at(m_size - 1);
108 const T& back()
const
111 return m_array.at(m_size - 1);
114 T& at(
const size_t i)
117 return m_array.at(i);
120 const T& at(
const size_t i)
const
123 return m_array.at(i);
126 T& operator[](
const size_t i)
132 const T& operator[](
const size_t i)
const
138 template <
typename U,
class UnaryOperation>
139 auto transformed(UnaryOperation op) {
141 result.resize(size());
142 for (
size_t i = 0; i < size(); ++i) {
143 result[i] = op(at(i));
151 static_assert(D <= N,
"Invalid size");
152 return to_tuple_helper(std::make_index_sequence<D>());
156 template <
size_t... Indices>
157 auto to_tuple_helper(std::index_sequence<Indices...>) {
158 return std::make_tuple(m_array[Indices]...);
162 using iterator =
typename std::array<T, N>::iterator;
163 using const_iterator =
typename std::array<T, N>::const_iterator;
164 iterator begin() {
return m_array.begin(); }
165 iterator end() {
return m_array.begin() + m_size; }
166 const_iterator begin()
const {
return m_array.begin(); }
167 const_iterator end()
const {
return m_array.begin() + m_size; }
170template <
class T,
size_t N>
173 return (lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin()));
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
#define la_debug_assert(...)
Debug assertion check.
Definition: assert.h:189
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: project.cpp:27
Stack-allocated vector with a maximum size.
Definition: StackVector.h:36