3#ifndef DUNE_PDELAB_BACKEND_ISTL_VECTORITERATOR_HH
4#define DUNE_PDELAB_BACKEND_ISTL_VECTORITERATOR_HH
10#include <dune/pdelab/backend/istl/tags.hh>
20 template<
typename T,
bool is_const,
typename Tag,
typename... Iterators>
21 struct _extract_iterators;
23 template<
typename T,
typename... Iterators>
24 struct _extract_iterators<T,true,tags::block_vector,Iterators...>
25 :
public _extract_iterators<typename T::block_type,
27 typename tags::container<typename T::block_type>::type::base_tag,
28 Iterators..., typename T::const_iterator
32 template<
typename T,
typename... Iterators>
33 struct _extract_iterators<T,false,tags::block_vector,Iterators...>
34 :
public _extract_iterators<typename T::block_type,
36 typename tags::container<typename T::block_type>::type::base_tag,
37 Iterators..., typename T::iterator
41 template<
typename T,
typename... Iterators>
42 struct _extract_iterators<T,true,tags::field_vector,Iterators...>
44 typedef std::tuple<Iterators...,
typename T::const_iterator> type;
47 template<
typename T,
typename... Iterators>
48 struct _extract_iterators<T,false,tags::field_vector,Iterators...>
50 typedef std::tuple<Iterators...,
typename T::iterator> type;
54 template<
typename T,
typename... Iterators>
55 struct _extract_iterators<T,true,tags::dynamic_vector,Iterators...>
57 typedef std::tuple<Iterators...,
typename T::const_iterator> type;
60 template<
typename T,
typename... Iterators>
61 struct _extract_iterators<T,false,tags::dynamic_vector,Iterators...>
63 typedef std::tuple<Iterators...,
typename T::iterator> type;
68 struct extract_iterators
69 :
public _extract_iterators<V,false,typename tags::container<V>::type::base_tag>
73 struct extract_iterators<const V>
74 :
public _extract_iterators<V,true,typename tags::container<V>::type::base_tag>
79 struct vector_iterator_base
82 typedef V& vector_reference;
83 typedef typename tags::container<V>::type::base_tag vector_tag;
84 static const bool is_const =
false;
85 using iterator_category = std::forward_iterator_tag;
86 using value_type =
typename V::field_type;
87 using difference_type =
typename std::ptrdiff_t;
88 using pointer =
typename V::field_type*;
89 using reference =
typename V::field_type&;
93 struct vector_iterator_base<const V>
96 typedef const V& vector_reference;
97 typedef typename tags::container<V>::type::base_tag vector_tag;
98 static const bool is_const =
true;
99 using iterator_category = std::forward_iterator_tag;
100 using value_type =
typename V::field_type;
101 using difference_type =
typename std::ptrdiff_t;
102 using pointer =
const typename V::field_type*;
103 using reference =
const typename V::field_type&;
109 class vector_iterator
110 :
public impl::vector_iterator_base<V>
113 typedef impl::vector_iterator_base<V> BaseT;
114 typedef typename BaseT::vector vector;
115 typedef typename BaseT::vector_reference vector_reference;
116 typedef typename BaseT::vector_tag vector_tag;
117 typedef typename impl::extract_iterators<V>::type Iterators;
118 static const bool is_const = BaseT::is_const;
121 friend class vector_iterator;
125 vector_iterator(vector_reference vector,
bool at_end)
130 if (!start(vector_tag(),level<0>(),vector))
139 vector_iterator(
const vector_iterator<W>& r,
typename std::enable_if<is_const && !std::is_same<V,W>::value && std::is_same<vector,W>::value,
void*>::type =
nullptr)
141 , _current(r._current)
142 , _iterators(r._iterators)
151 typename std::enable_if<
152 is_const && !std::is_same<vector,W>::value && std::is_same<vector,W>::value,
155 operator=(
const vector_iterator<W>& r)
158 _current =r._current;
159 _iterators = r._iterators;
165 typename BaseT::pointer operator->()
const
171 typename BaseT::reference operator*()
const
177 vector_iterator& operator++()
183 vector_iterator operator++(
int)
185 vector_iterator tmp(*
this);
191 typename std::enable_if<
192 std::is_same<vector,typename vector_iterator<W>::vector>::value,
201 return _current == r._current;
208 typename std::enable_if<
209 std::is_same<vector,typename vector_iterator<W>::vector>::value,
219 template<std::
size_t l>
221 :
public std::integral_constant<std::size_t,l>
227 if (!advance(vector_tag(),level<0>()))
231 template<std::
size_t l,
typename Block>
232 bool start_leaf(level<l>, Block& block)
234 typedef typename std::tuple_element<l,Iterators>::type iterator;
235 iterator& it = std::get<l>(_iterators);
236 iterator& end = std::get<l>(_end);
249 template<std::
size_t l,
typename Block>
250 bool start(tags::field_vector_n, level<l>, Block& block)
252 return start_leaf(level<l>(),block);
255 template<std::
size_t l,
typename Block>
256 bool start(tags::dynamic_vector, level<l>, Block& block)
258 return start_leaf(level<l>(),block);
261 template<std::
size_t l,
typename Block>
262 bool start(tags::field_vector_1, level<l>, Block& block)
264 _current = &(block[0]);
269 template<std::
size_t l,
typename Block>
270 bool start(tags::block_vector, level<l>, Block& block)
272 typedef typename std::tuple_element<l,Iterators>::type iterator;
273 iterator& it = std::get<l>(_iterators);
274 iterator& end = std::get<l>(_end);
281 if (start(container_tag(*it),level<l+1>(),*it))
291 template<std::
size_t l>
292 bool advance_leaf(level<l>)
294 typedef typename std::tuple_element<l,Iterators>::type iterator;
295 iterator& it = std::get<l>(_iterators);
296 const iterator& end = std::get<l>(_end);
308 template<std::
size_t l>
309 bool advance(tags::field_vector_n, level<l>)
311 return advance_leaf(level<l>());
314 template<std::
size_t l>
315 bool advance(tags::dynamic_vector, level<l>)
317 return advance_leaf(level<l>());
320 template<std::
size_t l>
321 bool advance(tags::field_vector_1, level<l>)
327 template<std::
size_t l>
328 bool advance(tags::block_vector, level<l>)
330 typedef typename std::tuple_element<l,Iterators>::type iterator;
331 iterator& it = std::get<l>(_iterators);
332 iterator& end = std::get<l>(_end);
334 if (advance(container_tag(*it),level<l+1>()))
341 if (start(container_tag(*it),level<l+1>(),*it))
352 typename BaseT::pointer _current;
353 Iterators _iterators;
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:238
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:260
Dune namespace.
Definition: alignedallocator.hh:13