33 static const size_t alignment = internal::plain_enum_max(EIGEN_ALIGNOF(T),
sizeof(
void*));
37 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit MaxSizeVector(
size_t n)
38 : m_reserve(n), m_size(0), m_data(
static_cast<T*
>(internal::handmade_aligned_malloc(n *
sizeof(T), alignment))) {}
42 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE MaxSizeVector(
size_t n,
const T& init)
43 : m_reserve(n), m_size(n), m_data(
static_cast<T*
>(internal::handmade_aligned_malloc(n *
sizeof(T), alignment))) {
46 for (; i < m_size; ++i) {
47 new (&m_data[i]) T(init);
55 internal::handmade_aligned_free(m_data);
61 MaxSizeVector(
const MaxSizeVector&) =
delete;
62 MaxSizeVector& operator=(
const MaxSizeVector&) =
delete;
64 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~MaxSizeVector() {
65 for (
size_t i = m_size; i > 0; --i) {
68 internal::handmade_aligned_free(m_data);
71 void resize(
size_t n) {
72 eigen_assert(n <= m_reserve);
73 for (; m_size < n; ++m_size) {
74 new (&m_data[m_size]) T;
76 for (; m_size > n; --m_size) {
77 m_data[m_size - 1].~T();
79 eigen_assert(m_size == n);
83 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void push_back(
const T& t) {
84 eigen_assert(m_size < m_reserve);
85 new (&m_data[m_size]) T(t);
90 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void emplace_back(
const X& x) {
91 eigen_assert(m_size < m_reserve);
92 new (&m_data[m_size]) T(x);
96 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T& operator[](
size_t i)
const {
97 eigen_assert(i < m_size);
101 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& operator[](
size_t i) {
102 eigen_assert(i < m_size);
106 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& back() {
107 eigen_assert(m_size > 0);
108 return m_data[m_size - 1];
111 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T& back()
const {
112 eigen_assert(m_size > 0);
113 return m_data[m_size - 1];
116 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pop_back() {
117 eigen_assert(m_size > 0);
118 m_data[--m_size].~T();
121 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t size()
const {
return m_size; }
123 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool empty()
const {
return m_size == 0; }
125 EIGEN_DEVICE_FUNC
constexpr T* data() {
return m_data; }
127 EIGEN_DEVICE_FUNC
constexpr const T* data()
const {
return m_data; }
129 EIGEN_DEVICE_FUNC
constexpr T* begin() {
return m_data; }
131 EIGEN_DEVICE_FUNC
constexpr T* end() {
return m_data + m_size; }
133 EIGEN_DEVICE_FUNC
constexpr const T* begin()
const {
return m_data; }
135 EIGEN_DEVICE_FUNC
constexpr const T* end()
const {
return m_data + m_size; }