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 size_t size()
const {
return m_size; }
57 void clear() { m_size = 0; }
59 void resize(
const size_t i)
65 void push_back(
const T& v)
68 m_array[m_size++] = v;
71 template <
class...
Args>
72 void emplace_back(
Args&&... args)
75 m_array[m_size++] = T(std::forward<Args>(args)...);
84 T* data() {
return m_array.data(); }
86 const T* data()
const {
return m_array.data(); }
91 return m_array.front();
94 const T& front()
const
97 return m_array.front();
103 return m_array.at(m_size - 1);
106 const T& back()
const
109 return m_array.at(m_size - 1);
112 T& at(
const size_t i)
115 return m_array.at(i);
118 const T& at(
const size_t i)
const
121 return m_array.at(i);
124 T& operator[](
const size_t i)
130 const T& operator[](
const size_t i)
const
136 template <
typename U,
class UnaryOperation>
137 auto transformed(UnaryOperation op) {
139 result.resize(size());
140 for (
size_t i = 0; i < size(); ++i) {
141 result[i] = op(at(i));
149 static_assert(D <= N,
"Invalid size");
150 return to_tuple_helper(std::make_index_sequence<D>());
154 template <
size_t... Indices>
155 auto to_tuple_helper(std::index_sequence<Indices...>) {
156 return std::make_tuple(m_array[Indices]...);
160 using iterator =
typename std::array<T, N>::iterator;
161 using const_iterator =
typename std::array<T, N>::const_iterator;
162 iterator begin() {
return m_array.begin(); }
163 iterator end() {
return m_array.begin() + m_size; }
164 const_iterator begin()
const {
return m_array.begin(); }
165 const_iterator end()
const {
return m_array.begin() + m_size; }
168template <
class T,
size_t N>
171 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