5#ifndef DUNE_ISTL_BASEARRAY_HH
6#define DUNE_ISTL_BASEARRAY_HH
14#include "istlexception.hh"
50 template<
class B,
class A=std::allocator<B> >
51 class base_array_unmanaged
58 typedef B member_type;
61 typedef A allocator_type;
64 typedef typename A::size_type size_type;
70 using const_reference =
const B&;
75 reference operator[] (size_type i)
77#ifdef DUNE_ISTL_WITH_CHECKING
78 if (i>=n)
DUNE_THROW(ISTLError,
"index out of range");
84 const_reference operator[] (size_type i)
const
86#ifdef DUNE_ISTL_WITH_CHECKING
87 if (i>=n)
DUNE_THROW(ISTLError,
"index out of range");
95 :
public RandomAccessIteratorFacade<RealIterator<T>, T>
99 typedef typename std::remove_const<T>::type ValueType;
101 friend class RandomAccessIteratorFacade<RealIterator<const ValueType>, const ValueType>;
102 friend class RandomAccessIteratorFacade<RealIterator<ValueType>, ValueType>;
103 friend class RealIterator<const ValueType>;
104 friend class RealIterator<ValueType>;
111 RealIterator (
const B* _p, B* _i) : p(_p), i(_i)
114 RealIterator(
const RealIterator<ValueType>& it)
119 size_type index ()
const
125 bool equals (
const RealIterator<ValueType>& other)
const
132 bool equals (
const RealIterator<const ValueType>& other)
const
138 std::ptrdiff_t distanceTo(
const RealIterator& o)
const
157 reference
elementAt (std::ptrdiff_t offset)
const
163 reference dereference ()
const
168 void advance(std::ptrdiff_t d)
178 typedef RealIterator<B> iterator;
184 return iterator(p,p);
190 return iterator(p,p+n);
195 iterator beforeEnd ()
197 return iterator(p,p+n-1);
202 iterator beforeBegin ()
204 return iterator(p,p-1);
208 iterator find (size_type i)
214 typedef RealIterator<const B> const_iterator;
217 const_iterator begin ()
const
219 return const_iterator(p,p+0);
223 const_iterator end ()
const
225 return const_iterator(p,p+n);
230 const_iterator beforeEnd ()
const
232 return const_iterator(p,p+n-1);
237 const_iterator beforeBegin ()
const
239 return const_iterator(p,p-1);
243 const_iterator find (size_type i)
const
245 return const_iterator(p,p+
std::min(i,n));
252 size_type size ()
const
258 const B* data()
const
271 base_array_unmanaged ()
275 base_array_unmanaged (size_type n_, B* p_)
305 template<
class B,
class A=std::allocator<B> >
306 class compressed_base_array_unmanaged
313 typedef B member_type;
316 typedef A allocator_type;
319 typedef typename A::size_type size_type;
322 using reference = B&;
325 using const_reference =
const B&;
330 reference operator[] (size_type i)
332 const size_type* lb = std::lower_bound(j, j+n, i);
333 if (lb == j+n || *lb != i)
334 DUNE_THROW(ISTLError,
"index "<<i<<
" not in compressed array");
339 const_reference operator[] (size_type i)
const
341 const size_type* lb = std::lower_bound(j, j+n, i);
342 if (lb == j+n || *lb != i)
343 DUNE_THROW(ISTLError,
"index "<<i<<
" not in compressed array");
350 :
public BidirectionalIteratorFacade<RealIterator<T>, T>
354 typedef typename std::remove_const<T>::type ValueType;
356 friend class BidirectionalIteratorFacade<RealIterator<const ValueType>, const ValueType>;
357 friend class BidirectionalIteratorFacade<RealIterator<ValueType>, ValueType>;
358 friend class RealIterator<const ValueType>;
359 friend class RealIterator<ValueType>;
367 RealIterator (B* _p, size_type* _j, size_type _i)
368 : p(_p), j(_j), i(_i)
374 RealIterator(
const RealIterator<ValueType>& it)
375 : p(it.p), j(it.j), i(it.i)
380 bool equals (
const RealIterator<ValueType>& it)
const
387 bool equals (
const RealIterator<const ValueType>& it)
const
395 size_type index ()
const
401 void setindex (size_type k)
413 size_type offset ()
const
432 reference dereference ()
const
443 typedef RealIterator<B> iterator;
448 return iterator(p,j,0);
454 return iterator(p,j,n);
459 iterator beforeEnd ()
461 return iterator(p,j,n-1);
466 iterator beforeBegin ()
468 return iterator(p,j,-1);
472 iterator find (size_type i)
474 const size_type* lb = std::lower_bound(j, j+n, i);
475 return (lb != j+n && *lb == i)
481 typedef RealIterator<const B> const_iterator;
484 const_iterator begin ()
const
486 return const_iterator(p,j,0);
490 const_iterator end ()
const
492 return const_iterator(p,j,n);
497 const_iterator beforeEnd ()
const
499 return const_iterator(p,j,n-1);
504 const_iterator beforeBegin ()
const
506 return const_iterator(p,j,-1);
510 const_iterator find (size_type i)
const
512 const size_type* lb = std::lower_bound(j, j+n, i);
513 return (lb != j+n && *lb == i)
514 ? const_iterator(p,j,lb-j)
521 size_type size ()
const
528 compressed_base_array_unmanaged ()
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:402
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:135
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:89
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignedallocator.hh:13