Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef EIGEN_STDVECTOR_H
00027 #define EIGEN_STDVECTOR_H
00028
00029 #include "Eigen/src/StlSupport/details.h"
00030
00036 #define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...) \
00037 namespace std \
00038 { \
00039 template<> \
00040 class vector<__VA_ARGS__, std::allocator<__VA_ARGS__> > \
00041 : public vector<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
00042 { \
00043 typedef vector<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > vector_base; \
00044 public: \
00045 typedef __VA_ARGS__ value_type; \
00046 typedef vector_base::allocator_type allocator_type; \
00047 typedef vector_base::size_type size_type; \
00048 typedef vector_base::iterator iterator; \
00049 explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {} \
00050 template<typename InputIterator> \
00051 vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : vector_base(first, last, a) {} \
00052 vector(const vector& c) : vector_base(c) {} \
00053 explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {} \
00054 vector(iterator start, iterator end) : vector_base(start, end) {} \
00055 vector& operator=(const vector& x) { \
00056 vector_base::operator=(x); \
00057 return *this; \
00058 } \
00059 }; \
00060 }
00061
00062 namespace std {
00063
00064 #define EIGEN_STD_VECTOR_SPECIALIZATION_BODY \
00065 public: \
00066 typedef T value_type; \
00067 typedef typename vector_base::allocator_type allocator_type; \
00068 typedef typename vector_base::size_type size_type; \
00069 typedef typename vector_base::iterator iterator; \
00070 typedef typename vector_base::const_iterator const_iterator; \
00071 explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {} \
00072 template<typename InputIterator> \
00073 vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \
00074 : vector_base(first, last, a) {} \
00075 vector(const vector& c) : vector_base(c) {} \
00076 explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {} \
00077 vector(iterator start, iterator end) : vector_base(start, end) {} \
00078 vector& operator=(const vector& x) { \
00079 vector_base::operator=(x); \
00080 return *this; \
00081 }
00082
00083 template<typename T>
00084 class vector<T,EIGEN_ALIGNED_ALLOCATOR<T> >
00085 : public vector<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00086 Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> >
00087 {
00088 typedef vector<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00089 Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > vector_base;
00090 EIGEN_STD_VECTOR_SPECIALIZATION_BODY
00091
00092 void resize(size_type new_size)
00093 { resize(new_size, T()); }
00094
00095 #if defined(_VECTOR_)
00096
00097 void resize(size_type new_size, const value_type& x)
00098 {
00099 if (vector_base::size() < new_size)
00100 vector_base::_Insert_n(vector_base::end(), new_size - vector_base::size(), x);
00101 else if (new_size < vector_base::size())
00102 vector_base::erase(vector_base::begin() + new_size, vector_base::end());
00103 }
00104 void push_back(const value_type& x)
00105 { vector_base::push_back(x); }
00106 using vector_base::insert;
00107 iterator insert(const_iterator position, const value_type& x)
00108 { return vector_base::insert(position,x); }
00109 void insert(const_iterator position, size_type new_size, const value_type& x)
00110 { vector_base::insert(position, new_size, x); }
00111 #elif defined(_GLIBCXX_VECTOR) && (!(EIGEN_GNUC_AT_LEAST(4,1)))
00112
00113
00114 void resize(size_type new_size, const value_type& x)
00115 {
00116 vector_base::resize(new_size,x);
00117 }
00118 #elif defined(_GLIBCXX_VECTOR) && EIGEN_GNUC_AT_LEAST(4,2)
00119
00120 void resize(size_type new_size, const value_type& x)
00121 {
00122 if (new_size < vector_base::size())
00123 vector_base::_M_erase_at_end(this->_M_impl._M_start + new_size);
00124 else
00125 vector_base::insert(vector_base::end(), new_size - vector_base::size(), x);
00126 }
00127 #else
00128
00129
00130 void resize(size_type new_size, const value_type& x)
00131 {
00132 if (new_size < vector_base::size())
00133 vector_base::erase(vector_base::begin() + new_size, vector_base::end());
00134 else if (new_size > vector_base::size())
00135 vector_base::insert(vector_base::end(), new_size - vector_base::size(), x);
00136 }
00137 #endif
00138 };
00139 }
00140
00141 #endif // EIGEN_STDVECTOR_H