32 static const size_t alignment = internal::plain_enum_max(EIGEN_ALIGNOF(T),
sizeof(
void*));
36 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit MaxSizeVector(
size_t n)
37 : reserve_(n), size_(0), data_(
static_cast<T*
>(internal::handmade_aligned_malloc(n *
sizeof(T), alignment))) {}
41 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
MaxSizeVector(
size_t n,
const T& init)
42 : reserve_(n), size_(n), data_(
static_cast<T*
>(internal::handmade_aligned_malloc(n *
sizeof(T), alignment))) {
45 for (; i < size_; ++i) {
46 new (&data_[i]) T(init);
51 for (; (i + 1) > 0; --i) {
54 internal::handmade_aligned_free(data_);
60 for (
size_t i = size_; i > 0; --i) {
63 internal::handmade_aligned_free(data_);
66 void resize(
size_t n) {
67 eigen_assert(n <= reserve_);
68 for (; size_ < n; ++size_) {
69 new (&data_[size_]) T;
71 for (; size_ > n; --size_) {
72 data_[size_ - 1].~T();
74 eigen_assert(size_ == n);
78 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void push_back(
const T& t) {
79 eigen_assert(size_ < reserve_);
80 new (&data_[size_++]) T(t);
85 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void emplace_back(
const X& x) {
86 eigen_assert(size_ < reserve_);
87 new (&data_[size_++]) T(x);
90 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T& operator[](
size_t i)
const {
91 eigen_assert(i < size_);
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& operator[](
size_t i) {
96 eigen_assert(i < size_);
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& back() {
101 eigen_assert(size_ > 0);
102 return data_[size_ - 1];
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T& back()
const {
106 eigen_assert(size_ > 0);
107 return data_[size_ - 1];
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void pop_back() {
111 eigen_assert(size_ > 0);
115 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t size()
const {
return size_; }
117 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool empty()
const {
return size_ == 0; }
119 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* data() {
return data_; }
121 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T* data()
const {
return data_; }
123 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* begin() {
return data_; }
125 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* end() {
return data_ + size_; }
127 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T* begin()
const {
return data_; }
129 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T* end()
const {
return data_ + size_; }