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