details.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. // Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com>
  6. //
  7. // This Source Code Form is subject to the terms of the Mozilla
  8. // Public License v. 2.0. If a copy of the MPL was not distributed
  9. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  10. #ifndef EIGEN_STL_DETAILS_H
  11. #define EIGEN_STL_DETAILS_H
  12. #ifndef EIGEN_ALIGNED_ALLOCATOR
  13. #define EIGEN_ALIGNED_ALLOCATOR Eigen::aligned_allocator
  14. #endif
  15. namespace Eigen {
  16. // This one is needed to prevent reimplementing the whole std::vector.
  17. template <class T>
  18. class aligned_allocator_indirection : public EIGEN_ALIGNED_ALLOCATOR<T>
  19. {
  20. public:
  21. typedef std::size_t size_type;
  22. typedef std::ptrdiff_t difference_type;
  23. typedef T* pointer;
  24. typedef const T* const_pointer;
  25. typedef T& reference;
  26. typedef const T& const_reference;
  27. typedef T value_type;
  28. template<class U>
  29. struct rebind
  30. {
  31. typedef aligned_allocator_indirection<U> other;
  32. };
  33. aligned_allocator_indirection() {}
  34. aligned_allocator_indirection(const aligned_allocator_indirection& ) : EIGEN_ALIGNED_ALLOCATOR<T>() {}
  35. aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<T>& ) {}
  36. template<class U>
  37. aligned_allocator_indirection(const aligned_allocator_indirection<U>& ) {}
  38. template<class U>
  39. aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<U>& ) {}
  40. ~aligned_allocator_indirection() {}
  41. };
  42. #if EIGEN_COMP_MSVC
  43. // sometimes, MSVC detects, at compile time, that the argument x
  44. // in std::vector::resize(size_t s,T x) won't be aligned and generate an error
  45. // even if this function is never called. Whence this little wrapper.
  46. #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) \
  47. typename Eigen::internal::conditional< \
  48. Eigen::internal::is_arithmetic<T>::value, \
  49. T, \
  50. Eigen::internal::workaround_msvc_stl_support<T> \
  51. >::type
  52. namespace internal {
  53. template<typename T> struct workaround_msvc_stl_support : public T
  54. {
  55. inline workaround_msvc_stl_support() : T() {}
  56. inline workaround_msvc_stl_support(const T& other) : T(other) {}
  57. inline operator T& () { return *static_cast<T*>(this); }
  58. inline operator const T& () const { return *static_cast<const T*>(this); }
  59. template<typename OtherT>
  60. inline T& operator=(const OtherT& other)
  61. { T::operator=(other); return *this; }
  62. inline workaround_msvc_stl_support& operator=(const workaround_msvc_stl_support& other)
  63. { T::operator=(other); return *this; }
  64. };
  65. }
  66. #else
  67. #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) T
  68. #endif
  69. }
  70. #endif // EIGEN_STL_DETAILS_H