• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef EIGEN_STL_DETAILS_H
12 #define EIGEN_STL_DETAILS_H
13 
14 #ifndef EIGEN_ALIGNED_ALLOCATOR
15   #define EIGEN_ALIGNED_ALLOCATOR Eigen::aligned_allocator
16 #endif
17 
18 namespace Eigen {
19 
20   // This one is needed to prevent reimplementing the whole std::vector.
21   template <class T>
22   class aligned_allocator_indirection : public EIGEN_ALIGNED_ALLOCATOR<T>
23   {
24   public:
25     typedef std::size_t     size_type;
26     typedef std::ptrdiff_t  difference_type;
27     typedef T*              pointer;
28     typedef const T*        const_pointer;
29     typedef T&              reference;
30     typedef const T&        const_reference;
31     typedef T               value_type;
32 
33     template<class U>
34     struct rebind
35     {
36       typedef aligned_allocator_indirection<U> other;
37     };
38 
aligned_allocator_indirection()39     aligned_allocator_indirection() {}
aligned_allocator_indirection(const aligned_allocator_indirection &)40     aligned_allocator_indirection(const aligned_allocator_indirection& ) : EIGEN_ALIGNED_ALLOCATOR<T>() {}
aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<T> &)41     aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<T>& ) {}
42     template<class U>
aligned_allocator_indirection(const aligned_allocator_indirection<U> &)43     aligned_allocator_indirection(const aligned_allocator_indirection<U>& ) {}
44     template<class U>
aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<U> &)45     aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<U>& ) {}
~aligned_allocator_indirection()46     ~aligned_allocator_indirection() {}
47   };
48 
49 #if EIGEN_COMP_MSVC
50 
51   // sometimes, MSVC detects, at compile time, that the argument x
52   // in std::vector::resize(size_t s,T x) won't be aligned and generate an error
53   // even if this function is never called. Whence this little wrapper.
54 #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) \
55   typename Eigen::internal::conditional< \
56     Eigen::internal::is_arithmetic<T>::value, \
57     T, \
58     Eigen::internal::workaround_msvc_stl_support<T> \
59   >::type
60 
61   namespace internal {
62   template<typename T> struct workaround_msvc_stl_support : public T
63   {
workaround_msvc_stl_supportworkaround_msvc_stl_support64     inline workaround_msvc_stl_support() : T() {}
workaround_msvc_stl_supportworkaround_msvc_stl_support65     inline workaround_msvc_stl_support(const T& other) : T(other) {}
66     inline operator T& () { return *static_cast<T*>(this); }
67     inline operator const T& () const { return *static_cast<const T*>(this); }
68     template<typename OtherT>
69     inline T& operator=(const OtherT& other)
70     { T::operator=(other); return *this; }
71     inline workaround_msvc_stl_support& operator=(const workaround_msvc_stl_support& other)
72     { T::operator=(other); return *this; }
73   };
74   }
75 
76 #else
77 
78 #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) T
79 
80 #endif
81 
82 }
83 
84 #endif // EIGEN_STL_DETAILS_H
85