1
// This file is part of Eigen, a lightweight C++ template library
4
// Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com>
6
// Eigen is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 3 of the License, or (at your option) any later version.
11
// Alternatively, you can redistribute it and/or
12
// modify it under the terms of the GNU General Public License as
13
// published by the Free Software Foundation; either version 2 of
14
// the License, or (at your option) any later version.
16
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19
// GNU General Public License for more details.
21
// You should have received a copy of the GNU Lesser General Public
22
// License and a copy of the GNU General Public License along with
23
// Eigen. If not, see <http://www.gnu.org/licenses/>.
25
#ifndef EIGEN_STDLIST_H
26
#define EIGEN_STDLIST_H
28
#include "Eigen/src/StlSupport/details.h"
30
// Define the explicit instantiation (e.g. necessary for the Intel compiler)
31
#if defined(__INTEL_COMPILER) || defined(__GNUC__)
32
#define EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(...) template class std::list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> >;
34
#define EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(...)
38
* This section contains a convenience MACRO which allows an easy specialization of
39
* std::list such that for data types with alignment issues the correct allocator
40
* is used automatically.
42
#define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) \
43
EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(__VA_ARGS__) \
46
template<typename _Ay> \
47
class list<__VA_ARGS__, _Ay> \
48
: public list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
50
typedef list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > list_base; \
52
typedef __VA_ARGS__ value_type; \
53
typedef typename list_base::allocator_type allocator_type; \
54
typedef typename list_base::size_type size_type; \
55
typedef typename list_base::iterator iterator; \
56
explicit list(const allocator_type& a = allocator_type()) : list_base(a) {} \
57
template<typename InputIterator> \
58
list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : list_base(first, last, a) {} \
59
list(const list& c) : list_base(c) {} \
60
explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \
61
list(iterator start, iterator end) : list_base(start, end) {} \
62
list& operator=(const list& x) { \
63
list_base::operator=(x); \
69
// check whether we really need the std::vector specialization
70
#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&). */
75
#define EIGEN_STD_LIST_SPECIALIZATION_BODY \
77
typedef T value_type; \
78
typedef typename list_base::allocator_type allocator_type; \
79
typedef typename list_base::size_type size_type; \
80
typedef typename list_base::iterator iterator; \
81
typedef typename list_base::const_iterator const_iterator; \
82
explicit list(const allocator_type& a = allocator_type()) : list_base(a) {} \
83
template<typename InputIterator> \
84
list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \
85
: list_base(first, last, a) {} \
86
list(const list& c) : list_base(c) {} \
87
explicit list(size_type num, const value_type& val = value_type()) : list_base(num, val) {} \
88
list(iterator start, iterator end) : list_base(start, end) {} \
89
list& operator=(const list& x) { \
90
list_base::operator=(x); \
95
class list<T,EIGEN_ALIGNED_ALLOCATOR<T> >
96
: public list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
97
Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> >
99
typedef list<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T),
100
Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > list_base;
101
EIGEN_STD_LIST_SPECIALIZATION_BODY
103
void resize(size_type new_size)
104
{ resize(new_size, T()); }
106
void resize(size_type new_size, const value_type& x)
108
if (list_base::size() < new_size)
109
list_base::insert(list_base::end(), new_size - list_base::size(), x);
111
while (new_size < list_base::size()) list_base::pop_back();
115
// workaround MSVC std::list implementation
116
void push_back(const value_type& x)
117
{ list_base::push_back(x); }
118
using list_base::insert;
119
iterator insert(const_iterator position, const value_type& x)
120
{ return list_base::insert(position,x); }
121
void insert(const_iterator position, size_type new_size, const value_type& x)
122
{ list_base::insert(position, new_size, x); }
127
#endif // check whether specialization is actually required
129
#endif // EIGEN_STDLIST_H