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
80 :
public std::iterator<std::forward_iterator_tag,
81 typename V::field_type,
82 typename std::ptrdiff_t,
83 typename V::field_type*,
84 typename V::field_type&
88 typedef V& vector_reference;
89 typedef typename tags::container<V>::type::base_tag vector_tag;
90 static const bool is_const =
false;
94 struct vector_iterator_base<const V>
95 :
public std::iterator<std::forward_iterator_tag,
96 typename V::field_type,
97 typename std::ptrdiff_t,
98 const typename V::field_type*,
99 const typename V::field_type&
103 typedef const V& vector_reference;
104 typedef typename tags::container<V>::type::base_tag vector_tag;
105 static const bool is_const =
true;
111 class vector_iterator
112 :
public impl::vector_iterator_base<V>
115 typedef impl::vector_iterator_base<V> BaseT;
116 typedef typename BaseT::vector vector;
117 typedef typename BaseT::vector_reference vector_reference;
118 typedef typename BaseT::vector_tag vector_tag;
119 typedef typename impl::extract_iterators<V>::type Iterators;
120 static const bool is_const = BaseT::is_const;
123 friend class vector_iterator;
127 vector_iterator(vector_reference vector,
bool at_end)
132 if (!start(vector_tag(),level<0>(),vector))
141 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)
143 , _current(r._current)
144 , _iterators(r._iterators)
153 typename std::enable_if<
154 is_const && !std::is_same<vector,W>::value && std::is_same<vector,W>::value,
157 operator=(
const vector_iterator<W>& r)
160 _current =r._current;
161 _iterators = r._iterators;
167 typename BaseT::pointer operator->()
const
173 typename BaseT::reference operator*()
const
179 vector_iterator& operator++()
185 vector_iterator operator++(
int)
187 vector_iterator tmp(*
this);
193 typename std::enable_if<
194 std::is_same<vector,typename vector_iterator<W>::vector>::value,
203 return _current == r._current;
210 typename std::enable_if<
211 std::is_same<vector,typename vector_iterator<W>::vector>::value,
221 template<std::
size_t l>
223 :
public std::integral_constant<std::size_t,l>
229 if (!advance(vector_tag(),level<0>()))
233 template<std::
size_t l,
typename Block>
234 bool start_leaf(level<l>, Block& block)
236 typedef typename std::tuple_element<l,Iterators>::type iterator;
237 iterator& it = std::get<l>(_iterators);
238 iterator& end = std::get<l>(_end);
251 template<std::
size_t l,
typename Block>
252 bool start(tags::field_vector_n, level<l>, Block& block)
254 return start_leaf(level<l>(),block);
257 template<std::
size_t l,
typename Block>
258 bool start(tags::dynamic_vector, level<l>, Block& block)
260 return start_leaf(level<l>(),block);
263 template<std::
size_t l,
typename Block>
264 bool start(tags::field_vector_1, level<l>, Block& block)
266 _current = &(block[0]);
271 template<std::
size_t l,
typename Block>
272 bool start(tags::block_vector, level<l>, Block& block)
274 typedef typename std::tuple_element<l,Iterators>::type iterator;
275 iterator& it = std::get<l>(_iterators);
276 iterator& end = std::get<l>(_end);
283 if (start(container_tag(*it),level<l+1>(),*it))
293 template<std::
size_t l>
294 bool advance_leaf(level<l>)
296 typedef typename std::tuple_element<l,Iterators>::type iterator;
297 iterator& it = std::get<l>(_iterators);
298 const iterator& end = std::get<l>(_end);
310 template<std::
size_t l>
311 bool advance(tags::field_vector_n, level<l>)
313 return advance_leaf(level<l>());
316 template<std::
size_t l>
317 bool advance(tags::dynamic_vector, level<l>)
319 return advance_leaf(level<l>());
322 template<std::
size_t l>
323 bool advance(tags::field_vector_1, level<l>)
329 template<std::
size_t l>
330 bool advance(tags::block_vector, level<l>)
332 typedef typename std::tuple_element<l,Iterators>::type iterator;
333 iterator& it = std::get<l>(_iterators);
334 iterator& end = std::get<l>(_end);
336 if (advance(container_tag(*it),level<l+1>()))
343 if (start(container_tag(*it),level<l+1>(),*it))
354 typename BaseT::pointer _current;
355 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:235
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:257
Dune namespace.
Definition: alignedallocator.hh:11