Eigen::MaxSizeVector< T > Class Template Reference

The MaxSizeVector class. More...

Public Member Functions

Tback ()
 
const Tback () const
 
Tbegin ()
 
const Tbegin () const
 
Tdata ()
 
const Tdata () const
 
template<class X >
void emplace_back (const X &x)
 
bool empty () const
 
Tend ()
 
const Tend () const
 
 MaxSizeVector (size_t n)
 
 MaxSizeVector (size_t n, const T &init)
 
Toperator[] (size_t i)
 
const Toperator[] (size_t i) const
 
void pop_back ()
 
void push_back (const T &t)
 
void resize (size_t n)
 
size_t size () const
 
 ~MaxSizeVector ()
 

Private Attributes

Tdata_
 
size_t reserve_
 
size_t size_
 

Static Private Attributes

static const size_t alignment
 

Detailed Description

template<typename T>
class Eigen::MaxSizeVector< T >

The MaxSizeVector class.

The MaxSizeVector provides a subset of std::vector functionality.

The goal is to provide basic std::vector operations when using std::vector is not an option (e.g. on GPU or when compiling using FMA/AVX, as this can cause either compilation failures or illegal instruction failures).

Beware: The constructors are not API compatible with these of std::vector.

Definition at line 31 of file MaxSizeVector.h.

Constructor & Destructor Documentation

◆ MaxSizeVector() [1/2]

template<typename T >
Eigen::MaxSizeVector< T >::MaxSizeVector ( size_t  n)
inlineexplicit

Definition at line 36 of file MaxSizeVector.h.

37  : reserve_(n), size_(0),
38  data_(static_cast<T*>(internal::handmade_aligned_malloc(n * sizeof(T), alignment))) {
39  }
int n
static const size_t alignment
Definition: MaxSizeVector.h:32
void * handmade_aligned_malloc(std::size_t size, std::size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
Definition: Memory.h:150

◆ MaxSizeVector() [2/2]

template<typename T >
Eigen::MaxSizeVector< T >::MaxSizeVector ( size_t  n,
const T init 
)
inline

Definition at line 44 of file MaxSizeVector.h.

45  : reserve_(n), size_(n),
46  data_(static_cast<T*>(internal::handmade_aligned_malloc(n * sizeof(T), alignment))) {
47  size_t i = 0;
48  EIGEN_TRY
49  {
50  for(; i < size_; ++i) { new (&data_[i]) T(init); }
51  }
52  EIGEN_CATCH(...)
53  {
54  // Construction failed, destruct in reverse order:
55  for(; (i+1) > 0; --i) { data_[i-1].~T(); }
58  }
59  }
#define EIGEN_CATCH(X)
Definition: Macros.h:1256
#define EIGEN_THROW
Definition: Macros.h:1253
#define EIGEN_TRY
Definition: Macros.h:1255
Eigen::Triplet< double > T
void handmade_aligned_free(void *ptr)
Definition: Memory.h:165

◆ ~MaxSizeVector()

template<typename T >
Eigen::MaxSizeVector< T >::~MaxSizeVector ( )
inline

Definition at line 62 of file MaxSizeVector.h.

62  {
63  for (size_t i = size_; i > 0; --i) {
64  data_[i-1].~T();
65  }
67  }

Member Function Documentation

◆ back() [1/2]

template<typename T >
T& Eigen::MaxSizeVector< T >::back ( )
inline

Definition at line 109 of file MaxSizeVector.h.

109  {
110  eigen_assert(size_ > 0);
111  return data_[size_ - 1];
112  }
#define eigen_assert(x)
Definition: Macros.h:902

◆ back() [2/2]

template<typename T >
const T& Eigen::MaxSizeVector< T >::back ( ) const
inline

Definition at line 115 of file MaxSizeVector.h.

115  {
116  eigen_assert(size_ > 0);
117  return data_[size_ - 1];
118  }

◆ begin() [1/2]

template<typename T >
T* Eigen::MaxSizeVector< T >::begin ( )
inline

Definition at line 139 of file MaxSizeVector.h.

139 { return data_; }

◆ begin() [2/2]

template<typename T >
const T* Eigen::MaxSizeVector< T >::begin ( ) const
inline

Definition at line 145 of file MaxSizeVector.h.

145 { return data_; }

◆ data() [1/2]

template<typename T >
T* Eigen::MaxSizeVector< T >::data ( )
inline

Definition at line 133 of file MaxSizeVector.h.

133 { return data_; }

◆ data() [2/2]

template<typename T >
const T* Eigen::MaxSizeVector< T >::data ( ) const
inline

Definition at line 136 of file MaxSizeVector.h.

136 { return data_; }

◆ emplace_back()

template<typename T >
template<class X >
void Eigen::MaxSizeVector< T >::emplace_back ( const X x)
inline

Definition at line 90 of file MaxSizeVector.h.

90  {
92  new (&data_[size_++]) T(x);
93  }

◆ empty()

template<typename T >
bool Eigen::MaxSizeVector< T >::empty ( ) const
inline

Definition at line 130 of file MaxSizeVector.h.

130 { return size_ == 0; }

◆ end() [1/2]

template<typename T >
T* Eigen::MaxSizeVector< T >::end ( )
inline

Definition at line 142 of file MaxSizeVector.h.

142 { return data_ + size_; }

◆ end() [2/2]

template<typename T >
const T* Eigen::MaxSizeVector< T >::end ( ) const
inline

Definition at line 148 of file MaxSizeVector.h.

148 { return data_ + size_; }

◆ operator[]() [1/2]

template<typename T >
T& Eigen::MaxSizeVector< T >::operator[] ( size_t  i)
inline

Definition at line 103 of file MaxSizeVector.h.

103  {
104  eigen_assert(i < size_);
105  return data_[i];
106  }

◆ operator[]() [2/2]

template<typename T >
const T& Eigen::MaxSizeVector< T >::operator[] ( size_t  i) const
inline

Definition at line 97 of file MaxSizeVector.h.

97  {
98  eigen_assert(i < size_);
99  return data_[i];
100  }

◆ pop_back()

template<typename T >
void Eigen::MaxSizeVector< T >::pop_back ( )
inline

Definition at line 121 of file MaxSizeVector.h.

121  {
122  eigen_assert(size_ > 0);
123  data_[--size_].~T();
124  }

◆ push_back()

template<typename T >
void Eigen::MaxSizeVector< T >::push_back ( const T t)
inline

Definition at line 82 of file MaxSizeVector.h.

82  {
84  new (&data_[size_++]) T(t);
85  }

◆ resize()

template<typename T >
void Eigen::MaxSizeVector< T >::resize ( size_t  n)
inline

Definition at line 69 of file MaxSizeVector.h.

69  {
71  for (; size_ < n; ++size_) {
72  new (&data_[size_]) T;
73  }
74  for (; size_ > n; --size_) {
75  data_[size_-1].~T();
76  }
77  eigen_assert(size_ == n);
78  }

◆ size()

template<typename T >
size_t Eigen::MaxSizeVector< T >::size ( ) const
inline

Definition at line 127 of file MaxSizeVector.h.

127 { return size_; }

Member Data Documentation

◆ alignment

template<typename T >
const size_t Eigen::MaxSizeVector< T >::alignment
staticprivate

Definition at line 32 of file MaxSizeVector.h.

◆ data_

template<typename T >
T* Eigen::MaxSizeVector< T >::data_
private

Definition at line 153 of file MaxSizeVector.h.

◆ reserve_

template<typename T >
size_t Eigen::MaxSizeVector< T >::reserve_
private

Definition at line 151 of file MaxSizeVector.h.

◆ size_

template<typename T >
size_t Eigen::MaxSizeVector< T >::size_
private

Definition at line 152 of file MaxSizeVector.h.


The documentation for this class was generated from the following file: