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 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_STDDEQUE_H
00027 #define EIGEN_STDDEQUE_H
00028 
00029 #include "Eigen/src/StlSupport/details.h"
00030 
00031 // Define the explicit instantiation (e.g. necessary for the Intel compiler)
00032 #if defined(__INTEL_COMPILER) || defined(__GNUC__)
00033   #define EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(...) template class std::deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> >;
00034 #else
00035   #define EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(...)
00036 #endif
00037 
00043 #define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) \
00044 EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(__VA_ARGS__) \
00045 namespace std \
00046 { \
00047   template<typename _Ay> \
00048   class deque<__VA_ARGS__, _Ay>  \
00049     : public deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
00050   { \
00051     typedef deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > deque_base; \
00052   public: \
00053     typedef __VA_ARGS__ value_type; \
00054     typedef typename deque_base::allocator_type allocator_type; \
00055     typedef typename deque_base::size_type size_type;  \
00056     typedef typename deque_base::iterator iterator;  \
00057     explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {}  \
00058     template<typename InputIterator> \
00059     deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : deque_base(first, last, a) {} \
00060     deque(const deque& c) : deque_base(c) {}  \
00061     explicit deque(size_type num, const value_type& val = value_type()) : deque_base(num, val) {} \
00062     deque(iterator start, iterator end) : deque_base(start, end) {}  \
00063     deque& operator=(const deque& x) {  \
00064       deque_base::operator=(x);  \
00065       return *this;  \
00066     } \
00067   }; \
00068 }
00069 
00070 // check whether we really need the std::deque specialization
00071 #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&). */
00072 
00073 namespace std {
00074 
00075 #define EIGEN_STD_DEQUE_SPECIALIZATION_BODY \
00076   public:  \
00077     typedef T value_type; \
00078     typedef typename deque_base::allocator_type allocator_type; \
00079     typedef typename deque_base::size_type size_type;  \
00080     typedef typename deque_base::iterator iterator;  \
00081     typedef typename deque_base::const_iterator const_iterator;  \
00082     explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {}  \
00083     template<typename InputIterator> \
00084     deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \
00085     : deque_base(first, last, a) {} \
00086     deque(const deque& c) : deque_base(c) {}  \
00087     explicit deque(size_type num, const value_type& val = value_type()) : deque_base(num, val) {} \
00088     deque(iterator start, iterator end) : deque_base(start, end) {}  \
00089     deque& operator=(const deque& x) {  \
00090       deque_base::operator=(x);  \
00091       return *this;  \
00092     }
00093 
00094   template<typename T>
00095   class deque<T,EIGEN_ALIGNED_ALLOCATOR<T> >
00096     : public deque<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00097                    Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> >
00098 {
00099   typedef deque<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00100                 Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > deque_base;
00101   EIGEN_STD_DEQUE_SPECIALIZATION_BODY
00102 
00103   void resize(size_type new_size)
00104   { resize(new_size, T()); }
00105 
00106 #if defined(_DEQUE_)
00107   // workaround MSVC std::deque implementation
00108   void resize(size_type new_size, const value_type& x)
00109   {
00110     if (deque_base::size() < new_size)
00111       deque_base::_Insert_n(deque_base::end(), new_size - deque_base::size(), x);
00112     else if (new_size < deque_base::size())
00113       deque_base::erase(deque_base::begin() + new_size, deque_base::end());
00114   }
00115   void push_back(const value_type& x)
00116   { deque_base::push_back(x); } 
00117   void push_front(const value_type& x)
00118   { deque_base::push_front(x); }
00119   using deque_base::insert;  
00120   iterator insert(const_iterator position, const value_type& x)
00121   { return deque_base::insert(position,x); }
00122   void insert(const_iterator position, size_type new_size, const value_type& x)
00123   { deque_base::insert(position, new_size, x); }
00124 #elif defined(_GLIBCXX_DEQUE) && EIGEN_GNUC_AT_LEAST(4,2)
00125   // workaround GCC std::deque implementation
00126   void resize(size_type new_size, const value_type& x)
00127   {
00128     if (new_size < deque_base::size())
00129       deque_base::_M_erase_at_end(this->_M_impl._M_start + new_size);
00130     else
00131       deque_base::insert(deque_base::end(), new_size - deque_base::size(), x);
00132   }
00133 #else
00134   // either GCC 4.1 or non-GCC
00135   // default implementation which should always work.
00136   void resize(size_type new_size, const value_type& x)
00137   {
00138     if (new_size < deque_base::size())
00139       deque_base::erase(deque_base::begin() + new_size, deque_base::end());
00140     else if (new_size > deque_base::size())
00141       deque_base::insert(deque_base::end(), new_size - deque_base::size(), x);
00142   }
00143 #endif
00144   };
00145 }
00146 
00147 #endif // check whether specialization is actually required
00148 
00149 #endif // EIGEN_STDDEQUE_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:59