From 5b9cc65418be7539db01f87712ed32d3f22517a5 Mon Sep 17 00:00:00 2001 From: Hauke Heibel Date: Wed, 27 Jan 2010 20:34:05 +0100 Subject: Added EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION macro including unit tests and documentation. --- Eigen/StdVector | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Eigen/StdVector') diff --git a/Eigen/StdVector b/Eigen/StdVector index b6dbde8a2..04e356785 100644 --- a/Eigen/StdVector +++ b/Eigen/StdVector @@ -29,6 +29,45 @@ #include "Core" #include +// Define the explicit instantiation (e.g. necessary for the Intel compiler) +#if defined(__INTEL_COMPILER) || defined(__GNUC__) + #define EIGEN_EXPLICIT_STL_VECTOR_INSTANTIATION(...) template class std::vector<__VA_ARGS__, Eigen::aligned_allocator<__VA_ARGS__> >; +#else + #define EIGEN_EXPLICIT_STL_VECTOR_INSTANTIATION(...) +#endif + +/** + * This section contains a convenience MACRO which allows an easy specialization of + * std::vector such that for data types with alignment issues the correct allocator + * is used automatically. + */ +#define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...) \ +EIGEN_EXPLICIT_STL_VECTOR_INSTANTIATION(__VA_ARGS__) \ +namespace std \ +{ \ + template \ + class vector<__VA_ARGS__, _Ay> \ + : public vector<__VA_ARGS__, Eigen::aligned_allocator<__VA_ARGS__> > \ + { \ + typedef vector<__VA_ARGS__, Eigen::aligned_allocator<__VA_ARGS__> > vector_base; \ + public: \ + typedef __VA_ARGS__ value_type; \ + typedef typename vector_base::allocator_type allocator_type; \ + typedef typename vector_base::size_type size_type; \ + typedef typename vector_base::iterator iterator; \ + explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {} \ + template \ + vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : vector_base(first, last, a) {} \ + vector(const vector& c) : vector_base(c) {} \ + explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {} \ + vector(iterator start, iterator end) : vector_base(start, end) {} \ + vector& operator=(const vector& x) { \ + vector_base::operator=(x); \ + return *this; \ + } \ + }; \ +} + namespace Eigen { // This one is needed to prevent reimplementing the whole std::vector. -- cgit v1.2.3