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);
52 for (; (i + 1) > 0; --i) {
55 internal::handmade_aligned_free(m_data);
60 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~MaxSizeVector() {
61 for (
size_t i = m_size; i > 0; --i) {
64 internal::handmade_aligned_free(m_data);
67 void resize(
size_t n) {
68 eigen_assert(n <= m_reserve);
69 for (; m_size < n; ++m_size) {
70 new (&m_data[m_size]) T;
72 for (; m_size > n; --m_size) {
73 m_data[m_size - 1].~T();
75 eigen_assert(m_size == n);
79 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void push_back(
const T& t) {
80 eigen_assert(m_size < m_reserve);
81 new (&m_data[m_size++]) T(t);
85 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void emplace_back(
const X& x) {
86 eigen_assert(m_size < m_reserve);
87 new (&m_data[m_size++]) T(x);
90 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T& operator[](
size_t i)
const {
91 eigen_assert(i < m_size);
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& operator[](
size_t i) {
96 eigen_assert(i < m_size);
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& back() {
101 eigen_assert(m_size > 0);
102 return m_data[m_size - 1];
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T& back()
const {
106 eigen_assert(m_size > 0);
107 return m_data[m_size - 1];
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pop_back() {
111 eigen_assert(m_size > 0);
112 m_data[--m_size].~T();
115 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t size()
const {
return m_size; }
117 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool empty()
const {
return m_size == 0; }
119 EIGEN_DEVICE_FUNC
constexpr T* data() {
return m_data; }
121 EIGEN_DEVICE_FUNC
constexpr const T* data()
const {
return m_data; }
123 EIGEN_DEVICE_FUNC
constexpr T* begin() {
return m_data; }
125 EIGEN_DEVICE_FUNC
constexpr T* end() {
return m_data + m_size; }
127 EIGEN_DEVICE_FUNC
constexpr const T* begin()
const {
return m_data; }
129 EIGEN_DEVICE_FUNC
constexpr const T* end()
const {
return m_data + m_size; }