$treeview $search $mathjax
Eigen  3.2.3
$projectbrief
$projectbrief
$searchbox

details.h

00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_STL_DETAILS_H
00012 #define EIGEN_STL_DETAILS_H
00013 
00014 #ifndef EIGEN_ALIGNED_ALLOCATOR
00015   #define EIGEN_ALIGNED_ALLOCATOR Eigen::aligned_allocator
00016 #endif
00017 
00018 #include <cstddef> // for ptrdiff_t
00019 
00020 namespace Eigen {
00021 
00022   // This one is needed to prevent reimplementing the whole std::vector.
00023   template <class T>
00024   class aligned_allocator_indirection : public EIGEN_ALIGNED_ALLOCATOR<T>
00025   {
00026   public:
00027     typedef size_t    size_type;
00028     typedef ptrdiff_t difference_type;
00029     typedef T*        pointer;
00030     typedef const T*  const_pointer;
00031     typedef T&        reference;
00032     typedef const T&  const_reference;
00033     typedef T         value_type;
00034 
00035     template<class U>
00036     struct rebind
00037     {
00038       typedef aligned_allocator_indirection<U> other;
00039     };
00040 
00041     aligned_allocator_indirection() {}
00042     aligned_allocator_indirection(const aligned_allocator_indirection& ) : EIGEN_ALIGNED_ALLOCATOR<T>() {}
00043     aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<T>& ) {}
00044     template<class U>
00045     aligned_allocator_indirection(const aligned_allocator_indirection<U>& ) {}
00046     template<class U>
00047     aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<U>& ) {}
00048     ~aligned_allocator_indirection() {}
00049   };
00050 
00051 #ifdef _MSC_VER
00052 
00053   // sometimes, MSVC detects, at compile time, that the argument x
00054   // in std::vector::resize(size_t s,T x) won't be aligned and generate an error
00055   // even if this function is never called. Whence this little wrapper.
00056 #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) \
00057   typename Eigen::internal::conditional< \
00058     Eigen::internal::is_arithmetic<T>::value, \
00059     T, \
00060     Eigen::internal::workaround_msvc_stl_support<T> \
00061   >::type
00062 
00063   namespace internal {
00064   template<typename T> struct workaround_msvc_stl_support : public T
00065   {
00066     inline workaround_msvc_stl_support() : T() {}
00067     inline workaround_msvc_stl_support(const T& other) : T(other) {}
00068     inline operator T& () { return *static_cast<T*>(this); }
00069     inline operator const T& () const { return *static_cast<const T*>(this); }
00070     template<typename OtherT>
00071     inline T& operator=(const OtherT& other)
00072     { T::operator=(other); return *this; }
00073     inline workaround_msvc_stl_support& operator=(const workaround_msvc_stl_support& other)
00074     { T::operator=(other); return *this; }
00075   };
00076   }
00077 
00078 #else
00079 
00080 #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) T
00081 
00082 #endif
00083 
00084 }
00085 
00086 #endif // EIGEN_STL_DETAILS_H