Eigen  3.3.3
StdList.h
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 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_STDLIST_H
00011 #define EIGEN_STDLIST_H
00012 
00013 #include "details.h"
00014 
00020 #define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) \
00021 namespace std \
00022 { \
00023   template<> \
00024   class list<__VA_ARGS__, std::allocator<__VA_ARGS__> >           \
00025     : public list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
00026   { \
00027     typedef list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > list_base; \
00028   public: \
00029     typedef __VA_ARGS__ value_type; \
00030     typedef list_base::allocator_type allocator_type; \
00031     typedef list_base::size_type size_type;  \
00032     typedef list_base::iterator iterator;  \
00033     explicit list(const allocator_type& a = allocator_type()) : list_base(a) {}  \
00034     template<typename InputIterator> \
00035     list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : list_base(first, last, a) {} \
00036     list(const list& c) : list_base(c) {}  \
00037     explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \
00038     list(iterator start, iterator end) : list_base(start, end) {}  \
00039     list& operator=(const list& x) {  \
00040       list_base::operator=(x);  \
00041       return *this;  \
00042     } \
00043   }; \
00044 }
00045 
00046 // check whether we really need the std::list specialization
00047 #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&). */
00048 
00049 namespace std
00050 {
00051 
00052 #define EIGEN_STD_LIST_SPECIALIZATION_BODY \
00053   public:  \
00054     typedef T value_type; \
00055     typedef typename list_base::allocator_type allocator_type; \
00056     typedef typename list_base::size_type size_type;  \
00057     typedef typename list_base::iterator iterator;  \
00058     typedef typename list_base::const_iterator const_iterator;  \
00059     explicit list(const allocator_type& a = allocator_type()) : list_base(a) {}  \
00060     template<typename InputIterator> \
00061     list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \
00062     : list_base(first, last, a) {} \
00063     list(const list& c) : list_base(c) {}  \
00064     explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \
00065     list(iterator start, iterator end) : list_base(start, end) {}  \
00066     list& operator=(const list& x) {  \
00067     list_base::operator=(x);  \
00068     return *this; \
00069   }
00070 
00071   template<typename T>
00072   class list<T,EIGEN_ALIGNED_ALLOCATOR<T> >
00073     : public list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00074                   Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> >
00075   {
00076     typedef list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
00077                  Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > list_base;
00078     EIGEN_STD_LIST_SPECIALIZATION_BODY
00079 
00080     void resize(size_type new_size)
00081     { resize(new_size, T()); }
00082 
00083     void resize(size_type new_size, const value_type& x)
00084     {
00085       if (list_base::size() < new_size)
00086         list_base::insert(list_base::end(), new_size - list_base::size(), x);
00087       else
00088         while (new_size < list_base::size()) list_base::pop_back();
00089     }
00090 
00091 #if defined(_LIST_)
00092     // workaround MSVC std::list implementation
00093     void push_back(const value_type& x)
00094     { list_base::push_back(x); } 
00095     using list_base::insert;  
00096     iterator insert(const_iterator position, const value_type& x)
00097     { return list_base::insert(position,x); }
00098     void insert(const_iterator position, size_type new_size, const value_type& x)
00099     { list_base::insert(position, new_size, x); }
00100 #endif
00101   };
00102 }
00103 
00104 #endif // check whether specialization is actually required
00105 
00106 #endif // EIGEN_STDLIST_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends