Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/eigen3/Eigen/src/StlSupport/StdDeque.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 // Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com>
0006 //
0007 // This Source Code Form is subject to the terms of the Mozilla
0008 // Public License v. 2.0. If a copy of the MPL was not distributed
0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0010 
0011 #ifndef EIGEN_STDDEQUE_H
0012 #define EIGEN_STDDEQUE_H
0013 
0014 #include "details.h"
0015 
0016 /**
0017  * This section contains a convenience MACRO which allows an easy specialization of
0018  * std::deque such that for data types with alignment issues the correct allocator
0019  * is used automatically.
0020  */
0021 #define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) \
0022 namespace std \
0023 { \
0024   template<> \
0025   class deque<__VA_ARGS__, std::allocator<__VA_ARGS__> >           \
0026     : public deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
0027   { \
0028     typedef deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > deque_base; \
0029   public: \
0030     typedef __VA_ARGS__ value_type; \
0031     typedef deque_base::allocator_type allocator_type; \
0032     typedef deque_base::size_type size_type;  \
0033     typedef deque_base::iterator iterator;  \
0034     explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {}  \
0035     template<typename InputIterator> \
0036     deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : deque_base(first, last, a) {} \
0037     deque(const deque& c) : deque_base(c) {}  \
0038     explicit deque(size_type num, const value_type& val = value_type()) : deque_base(num, val) {} \
0039     deque(iterator start_, iterator end_) : deque_base(start_, end_) {}  \
0040     deque& operator=(const deque& x) {  \
0041       deque_base::operator=(x);  \
0042       return *this;  \
0043     } \
0044   }; \
0045 }
0046 
0047 // check whether we really need the std::deque specialization
0048 #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&). */
0049 
0050 namespace std {
0051 
0052 #define EIGEN_STD_DEQUE_SPECIALIZATION_BODY \
0053   public:  \
0054     typedef T value_type; \
0055     typedef typename deque_base::allocator_type allocator_type; \
0056     typedef typename deque_base::size_type size_type;  \
0057     typedef typename deque_base::iterator iterator;  \
0058     typedef typename deque_base::const_iterator const_iterator;  \
0059     explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {}  \
0060     template<typename InputIterator> \
0061     deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \
0062     : deque_base(first, last, a) {} \
0063     deque(const deque& c) : deque_base(c) {}  \
0064     explicit deque(size_type num, const value_type& val = value_type()) : deque_base(num, val) {} \
0065     deque(iterator start_, iterator end_) : deque_base(start_, end_) {}  \
0066     deque& operator=(const deque& x) {  \
0067       deque_base::operator=(x);  \
0068       return *this;  \
0069     }
0070 
0071   template<typename T>
0072   class deque<T,EIGEN_ALIGNED_ALLOCATOR<T> >
0073     : public deque<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
0074                    Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> >
0075 {
0076   typedef deque<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
0077                 Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > deque_base;
0078   EIGEN_STD_DEQUE_SPECIALIZATION_BODY
0079 
0080   void resize(size_type new_size)
0081   { resize(new_size, T()); }
0082 
0083 #if defined(_DEQUE_)
0084   // workaround MSVC std::deque implementation
0085   void resize(size_type new_size, const value_type& x)
0086   {
0087     if (deque_base::size() < new_size)
0088       deque_base::_Insert_n(deque_base::end(), new_size - deque_base::size(), x);
0089     else if (new_size < deque_base::size())
0090       deque_base::erase(deque_base::begin() + new_size, deque_base::end());
0091   }
0092   void push_back(const value_type& x)
0093   { deque_base::push_back(x); } 
0094   void push_front(const value_type& x)
0095   { deque_base::push_front(x); }
0096   using deque_base::insert;  
0097   iterator insert(const_iterator position, const value_type& x)
0098   { return deque_base::insert(position,x); }
0099   void insert(const_iterator position, size_type new_size, const value_type& x)
0100   { deque_base::insert(position, new_size, x); }
0101 #else
0102   // default implementation which should always work.
0103   void resize(size_type new_size, const value_type& x)
0104   {
0105     if (new_size < deque_base::size())
0106       deque_base::erase(deque_base::begin() + new_size, deque_base::end());
0107     else if (new_size > deque_base::size())
0108       deque_base::insert(deque_base::end(), new_size - deque_base::size(), x);
0109   }
0110 #endif
0111   };
0112 }
0113 
0114 #endif // check whether specialization is actually required
0115 
0116 #endif // EIGEN_STDDEQUE_H