3#ifndef DUNE_ISTL_BASEARRAY_HH
4#define DUNE_ISTL_BASEARRAY_HH
12#include "istlexception.hh"
48 template<
class B,
class A=std::allocator<B> >
49 class base_array_unmanaged
56 typedef B member_type;
59 typedef A allocator_type;
62 typedef typename A::size_type size_type;
68 using const_reference =
const B&;
73 reference operator[] (size_type i)
75#ifdef DUNE_ISTL_WITH_CHECKING
76 if (i>=n)
DUNE_THROW(ISTLError,
"index out of range");
82 const_reference operator[] (size_type i)
const
84#ifdef DUNE_ISTL_WITH_CHECKING
85 if (i>=n)
DUNE_THROW(ISTLError,
"index out of range");
93 :
public RandomAccessIteratorFacade<RealIterator<T>, T>
97 typedef typename std::remove_const<T>::type ValueType;
99 friend class RandomAccessIteratorFacade<RealIterator<const ValueType>, const ValueType>;
100 friend class RandomAccessIteratorFacade<RealIterator<ValueType>, ValueType>;
101 friend class RealIterator<const ValueType>;
102 friend class RealIterator<ValueType>;
109 RealIterator (
const B* _p, B* _i) : p(_p), i(_i)
112 RealIterator(
const RealIterator<ValueType>& it)
117 size_type index ()
const
123 bool equals (
const RealIterator<ValueType>& other)
const
130 bool equals (
const RealIterator<const ValueType>& other)
const
136 std::ptrdiff_t distanceTo(
const RealIterator& o)
const
155 reference
elementAt (std::ptrdiff_t offset)
const
161 reference dereference ()
const
166 void advance(std::ptrdiff_t d)
176 typedef RealIterator<B> iterator;
182 return iterator(p,p);
188 return iterator(p,p+n);
193 iterator beforeEnd ()
195 return iterator(p,p+n-1);
200 iterator beforeBegin ()
202 return iterator(p,p-1);
206 iterator find (size_type i)
212 typedef RealIterator<const B> const_iterator;
215 const_iterator begin ()
const
217 return const_iterator(p,p+0);
221 const_iterator end ()
const
223 return const_iterator(p,p+n);
228 const_iterator beforeEnd ()
const
230 return const_iterator(p,p+n-1);
235 const_iterator beforeBegin ()
const
237 return const_iterator(p,p-1);
241 const_iterator find (size_type i)
const
243 return const_iterator(p,p+
std::min(i,n));
250 size_type size ()
const
256 const B* data()
const
269 base_array_unmanaged ()
273 base_array_unmanaged (size_type n_, B* p_)
303 template<
class B,
class A=std::allocator<B> >
304 class compressed_base_array_unmanaged
311 typedef B member_type;
314 typedef A allocator_type;
317 typedef typename A::size_type size_type;
320 using reference = B&;
323 using const_reference =
const B&;
328 reference operator[] (size_type i)
330 const size_type* lb = std::lower_bound(j, j+n, i);
331 if (lb == j+n || *lb != i)
332 DUNE_THROW(ISTLError,
"index "<<i<<
" not in compressed array");
337 const_reference operator[] (size_type i)
const
339 const size_type* lb = std::lower_bound(j, j+n, i);
340 if (lb == j+n || *lb != i)
341 DUNE_THROW(ISTLError,
"index "<<i<<
" not in compressed array");
348 :
public BidirectionalIteratorFacade<RealIterator<T>, T>
352 typedef typename std::remove_const<T>::type ValueType;
354 friend class BidirectionalIteratorFacade<RealIterator<const ValueType>, const ValueType>;
355 friend class BidirectionalIteratorFacade<RealIterator<ValueType>, ValueType>;
356 friend class RealIterator<const ValueType>;
357 friend class RealIterator<ValueType>;
365 RealIterator (B* _p, size_type* _j, size_type _i)
366 : p(_p), j(_j), i(_i)
372 RealIterator(
const RealIterator<ValueType>& it)
373 : p(it.p), j(it.j), i(it.i)
378 bool equals (
const RealIterator<ValueType>& it)
const
385 bool equals (
const RealIterator<const ValueType>& it)
const
393 size_type index ()
const
399 void setindex (size_type k)
411 size_type offset ()
const
430 reference dereference ()
const
441 typedef RealIterator<B> iterator;
446 return iterator(p,j,0);
452 return iterator(p,j,n);
457 iterator beforeEnd ()
459 return iterator(p,j,n-1);
464 iterator beforeBegin ()
466 return iterator(p,j,-1);
470 iterator find (size_type i)
472 const size_type* lb = std::lower_bound(j, j+n, i);
473 return (lb != j+n && *lb == i)
479 typedef RealIterator<const B> const_iterator;
482 const_iterator begin ()
const
484 return const_iterator(p,j,0);
488 const_iterator end ()
const
490 return const_iterator(p,j,n);
495 const_iterator beforeEnd ()
const
497 return const_iterator(p,j,n-1);
502 const_iterator beforeBegin ()
const
504 return const_iterator(p,j,-1);
508 const_iterator find (size_type i)
const
510 const size_type* lb = std::lower_bound(j, j+n, i);
511 return (lb != j+n && *lb == i)
512 ? const_iterator(p,j,lb-j)
519 size_type size ()
const
526 compressed_base_array_unmanaged ()
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:401
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:134
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignedallocator.hh:14