Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/eigen3/Eigen/src/StlSupport/StdList.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 Hauke Heibel <hauke.heibel@googlemail.com>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_STDLIST_H
0011 #define EIGEN_STDLIST_H
0012 
0013 #include "details.h"
0014 
0015 /**
0016  * This section contains a convenience MACRO which allows an easy specialization of
0017  * std::list such that for data types with alignment issues the correct allocator
0018  * is used automatically.
0019  */
0020 #define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) \
0021 namespace std \
0022 { \
0023   template<> \
0024   class list<__VA_ARGS__, std::allocator<__VA_ARGS__> >           \
0025     : public list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
0026   { \
0027     typedef list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > list_base; \
0028   public: \
0029     typedef __VA_ARGS__ value_type; \
0030     typedef list_base::allocator_type allocator_type; \
0031     typedef list_base::size_type size_type;  \
0032     typedef list_base::iterator iterator;  \
0033     explicit list(const allocator_type& a = allocator_type()) : list_base(a) {}  \
0034     template<typename InputIterator> \
0035     list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : list_base(first, last, a) {} \
0036     list(const list& c) : list_base(c) {}  \
0037     explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \
0038     list(iterator start_, iterator end_) : list_base(start_, end_) {}  \
0039     list& operator=(const list& x) {  \
0040       list_base::operator=(x);  \
0041       return *this;  \
0042     } \
0043   }; \
0044 }
0045 
0046 // check whether we really need the std::list specialization
0047 #if !EIGEN_HAS_CXX11_CONTAINERS && !(defined(_GLIBCXX_LIST) && (!EIGEN_GNUC_AT_LEAST(4,1))) /* Note that before gcc-4.1 we already have: std::list::resize(size_type,const T&). */
0048 
0049 namespace std
0050 {
0051 
0052 #define EIGEN_STD_LIST_SPECIALIZATION_BODY \
0053   public:  \
0054     typedef T value_type; \
0055     typedef typename list_base::allocator_type allocator_type; \
0056     typedef typename list_base::size_type size_type;  \
0057     typedef typename list_base::iterator iterator;  \
0058     typedef typename list_base::const_iterator const_iterator;  \
0059     explicit list(const allocator_type& a = allocator_type()) : list_base(a) {}  \
0060     template<typename InputIterator> \
0061     list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \
0062     : list_base(first, last, a) {} \
0063     list(const list& c) : list_base(c) {}  \
0064     explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \
0065     list(iterator start_, iterator end_) : list_base(start_, end_) {}  \
0066     list& operator=(const list& x) {  \
0067     list_base::operator=(x);  \
0068     return *this; \
0069   }
0070 
0071   template<typename T>
0072   class list<T,EIGEN_ALIGNED_ALLOCATOR<T> >
0073     : public list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
0074                   Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> >
0075   {
0076     typedef list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
0077                  Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > list_base;
0078     EIGEN_STD_LIST_SPECIALIZATION_BODY
0079 
0080     void resize(size_type new_size)
0081     { resize(new_size, T()); }
0082 
0083     void resize(size_type new_size, const value_type& x)
0084     {
0085       if (list_base::size() < new_size)
0086         list_base::insert(list_base::end(), new_size - list_base::size(), x);
0087       else
0088         while (new_size < list_base::size()) list_base::pop_back();
0089     }
0090 
0091 #if defined(_LIST_)
0092     // workaround MSVC std::list implementation
0093     void push_back(const value_type& x)
0094     { list_base::push_back(x); } 
0095     using list_base::insert;  
0096     iterator insert(const_iterator position, const value_type& x)
0097     { return list_base::insert(position,x); }
0098     void insert(const_iterator position, size_type new_size, const value_type& x)
0099     { list_base::insert(position, new_size, x); }
0100 #endif
0101   };
0102 }
0103 
0104 #endif // check whether specialization is actually required
0105 
0106 #endif // EIGEN_STDLIST_H