StdDeque.h
Go to the documentation of this file.
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_STDDEQUE_H
00012 #define EIGEN_STDDEQUE_H
00013 
00014 #include "Eigen/src/StlSupport/details.h"
00015 
00016 // Define the explicit instantiation (e.g. necessary for the Intel compiler)
00017 #if defined(__INTEL_COMPILER) || defined(__GNUC__)
00018   #define EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(...) template class std::deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> >;
00019 #else
00020   #define EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(...)
00021 #endif
00022 
00028 #define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) \
00029 EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(__VA_ARGS__) \
00030 namespace std \
00031 { \
00032   template<typename _Ay> \
00033   class deque<__VA_ARGS__, _Ay>  \
00034     : public deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
00035   { \
00036     typedef deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > deque_base; \
00037   public: \
00038     typedef __VA_ARGS__ value_type; \
00039     typedef typename deque_base::allocator_type allocator_type; \
00040     typedef typename deque_base::size_type size_type;  \
00041     typedef typename deque_base::iterator iterator;  \
00042     explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {}  \
00043     template<typename InputIterator> \
00044     deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : deque_base(first, last, a) {} \
00045     deque(const deque& c) : deque_base(c) {}  \
00046     explicit deque(size_type num, const value_type& val = value_type()) : deque_base(num, val) {} \
00047     deque(iterator start, iterator end) : deque_base(start, end) {}  \
00048     deque& operator=(const deque& x) {  \
00049       deque_base::operator=(x);  \
00050       return *this;  \
00051     } \
00052   }; \
00053 }
00054 
00055 // check whether we really need the std::deque specialization
00056 #if !(defined(_GLIBCXX_DEQUE) && (!EIGEN_GNUC_AT_LEAST(4,1))) /* Note that before gcc-4.1 we already have: std::deque::resize(size_type,const T&). */
00057 
00058 namespace std {
00059 
00060 #define EIGEN_STD_DEQUE_SPECIALIZATION_BODY \
00061   public:  \
00062     typedef T value_type; \
00063     typedef typename deque_base::allocator_type allocator_type; \
00064     typedef typename deque_base::size_type size_type;  \
00065     typedef typename deque_base::iterator iterator;  \
00066     typedef typename deque_base::const_iterator const_iterator;  \
00067     explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {}  \
00068     template<typename InputIterator> \
00069     deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \
00070     : deque_base(first, last, a) {} \
00071     deque(const deque& c) : deque_base(c) {}  \
00072     explicit deque(size_type num, const value_type& val = value_type()) : deque_base(num, val) {} \
00073     deque(iterator start, iterator end) : deque_base(start, end) {}  \
00074     deque& operator=(const deque& x) {  \
00075       deque_base::operator=(x);  \
00076       return *this;  \
00077     }
00078 
00079   template<typename T>
00080   class deque<T,EIGEN_ALIGNED_ALLOCATOR<T> >
00081     : public deque<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00082                    Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> >
00083 {
00084   typedef deque<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00085                 Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > deque_base;
00086   EIGEN_STD_DEQUE_SPECIALIZATION_BODY
00087 
00088   void resize(size_type new_size)
00089   { resize(new_size, T()); }
00090 
00091 #if defined(_DEQUE_)
00092   // workaround MSVC std::deque implementation
00093   void resize(size_type new_size, const value_type& x)
00094   {
00095     if (deque_base::size() < new_size)
00096       deque_base::_Insert_n(deque_base::end(), new_size - deque_base::size(), x);
00097     else if (new_size < deque_base::size())
00098       deque_base::erase(deque_base::begin() + new_size, deque_base::end());
00099   }
00100   void push_back(const value_type& x)
00101   { deque_base::push_back(x); } 
00102   void push_front(const value_type& x)
00103   { deque_base::push_front(x); }
00104   using deque_base::insert;  
00105   iterator insert(const_iterator position, const value_type& x)
00106   { return deque_base::insert(position,x); }
00107   void insert(const_iterator position, size_type new_size, const value_type& x)
00108   { deque_base::insert(position, new_size, x); }
00109 #elif defined(_GLIBCXX_DEQUE) && EIGEN_GNUC_AT_LEAST(4,2)
00110   // workaround GCC std::deque implementation
00111   void resize(size_type new_size, const value_type& x)
00112   {
00113     if (new_size < deque_base::size())
00114       deque_base::_M_erase_at_end(this->_M_impl._M_start + new_size);
00115     else
00116       deque_base::insert(deque_base::end(), new_size - deque_base::size(), x);
00117   }
00118 #else
00119   // either GCC 4.1 or non-GCC
00120   // default implementation which should always work.
00121   void resize(size_type new_size, const value_type& x)
00122   {
00123     if (new_size < deque_base::size())
00124       deque_base::erase(deque_base::begin() + new_size, deque_base::end());
00125     else if (new_size > deque_base::size())
00126       deque_base::insert(deque_base::end(), new_size - deque_base::size(), x);
00127   }
00128 #endif
00129   };
00130 }
00131 
00132 #endif // check whether specialization is actually required
00133 
00134 #endif // EIGEN_STDDEQUE_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 12:00:57