StdList.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 Hauke Heibel <hauke.heibel@googlemail.com>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_STDLIST_H
00026 #define EIGEN_STDLIST_H
00027 
00028 #include "Eigen/src/StlSupport/details.h"
00029 
00030 // Define the explicit instantiation (e.g. necessary for the Intel compiler)
00031 #if defined(__INTEL_COMPILER) || defined(__GNUC__)
00032   #define EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(...) template class std::list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> >;
00033 #else
00034   #define EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(...)
00035 #endif
00036 
00042 #define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) \
00043 EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(__VA_ARGS__) \
00044 namespace std \
00045 { \
00046   template<typename _Ay> \
00047   class list<__VA_ARGS__, _Ay>  \
00048     : public list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
00049   { \
00050     typedef list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > list_base; \
00051   public: \
00052     typedef __VA_ARGS__ value_type; \
00053     typedef typename list_base::allocator_type allocator_type; \
00054     typedef typename list_base::size_type size_type;  \
00055     typedef typename list_base::iterator iterator;  \
00056     explicit list(const allocator_type& a = allocator_type()) : list_base(a) {}  \
00057     template<typename InputIterator> \
00058     list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : list_base(first, last, a) {} \
00059     list(const list& c) : list_base(c) {}  \
00060     explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \
00061     list(iterator start, iterator end) : list_base(start, end) {}  \
00062     list& operator=(const list& x) {  \
00063       list_base::operator=(x);  \
00064       return *this;  \
00065     } \
00066   }; \
00067 }
00068 
00069 // check whether we really need the std::vector specialization
00070 #if !(defined(_GLIBCXX_VECTOR) && (!EIGEN_GNUC_AT_LEAST(4,1))) /* Note that before gcc-4.1 we already have: std::list::resize(size_type,const T&). */
00071 
00072 namespace std
00073 {
00074 
00075 #define EIGEN_STD_LIST_SPECIALIZATION_BODY \
00076   public:  \
00077     typedef T value_type; \
00078     typedef typename list_base::allocator_type allocator_type; \
00079     typedef typename list_base::size_type size_type;  \
00080     typedef typename list_base::iterator iterator;  \
00081     typedef typename list_base::const_iterator const_iterator;  \
00082     explicit list(const allocator_type& a = allocator_type()) : list_base(a) {}  \
00083     template<typename InputIterator> \
00084     list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \
00085     : list_base(first, last, a) {} \
00086     list(const list& c) : list_base(c) {}  \
00087     explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \
00088     list(iterator start, iterator end) : list_base(start, end) {}  \
00089     list& operator=(const list& x) {  \
00090     list_base::operator=(x);  \
00091     return *this; \
00092   }
00093 
00094   template<typename T>
00095   class list<T,EIGEN_ALIGNED_ALLOCATOR<T> >
00096     : public list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00097                   Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> >
00098   {
00099     typedef list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00100                  Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > list_base;
00101     EIGEN_STD_LIST_SPECIALIZATION_BODY
00102 
00103     void resize(size_type new_size)
00104     { resize(new_size, T()); }
00105 
00106     void resize(size_type new_size, const value_type& x)
00107     {
00108       if (list_base::size() < new_size)
00109         list_base::insert(list_base::end(), new_size - list_base::size(), x);
00110       else
00111         while (new_size < list_base::size()) list_base::pop_back();
00112     }
00113 
00114 #if defined(_LIST_)
00115     // workaround MSVC std::list implementation
00116     void push_back(const value_type& x)
00117     { list_base::push_back(x); } 
00118     using list_base::insert;  
00119     iterator insert(const_iterator position, const value_type& x)
00120     { return list_base::insert(position,x); }
00121     void insert(const_iterator position, size_type new_size, const value_type& x)
00122     { list_base::insert(position, new_size, x); }
00123 #endif
00124   };
00125 }
00126 
00127 #endif // check whether specialization is actually required
00128 
00129 #endif // EIGEN_STDLIST_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:33:40