5#ifndef DUNE_ISTL_BASEARRAY_HH
6#define DUNE_ISTL_BASEARRAY_HH
15#include "istlexception.hh"
47 template<
class B,
class ST=std::
size_t >
48 class base_array_unmanaged
55 typedef B member_type;
64 using const_reference =
const B&;
69 reference operator[] (size_type i)
71#ifdef DUNE_ISTL_WITH_CHECKING
72 if (i>=n)
DUNE_THROW(ISTLError,
"index out of range");
78 const_reference operator[] (size_type i)
const
80#ifdef DUNE_ISTL_WITH_CHECKING
81 if (i>=n)
DUNE_THROW(ISTLError,
"index out of range");
89 :
public RandomAccessIteratorFacade<RealIterator<T>, T>
93 typedef typename std::remove_const<T>::type ValueType;
95 friend class RandomAccessIteratorFacade<RealIterator<const ValueType>, const ValueType>;
96 friend class RandomAccessIteratorFacade<RealIterator<ValueType>, ValueType>;
97 friend class RealIterator<const ValueType>;
98 friend class RealIterator<ValueType>;
101 RealIterator () =
default;
103 RealIterator (
const B* _p, B* _i)
108 std::enable_if_t<std::is_same_v<std::remove_const_t<T>, std::remove_const_t<T_>>,
int> = 0>
109 RealIterator (
const RealIterator<T_>& other)
110 : p(other.p), i(other.i)
114 std::enable_if_t<std::is_same_v<std::remove_const_t<T>, std::remove_const_t<T_>>,
int> = 0>
115 RealIterator& operator= (
const RealIterator<T_>& other)
123 size_type index ()
const
129 bool equals (
const RealIterator<ValueType>& other)
const
136 bool equals (
const RealIterator<const ValueType>& other)
const
142 std::ptrdiff_t distanceTo(
const RealIterator& o)
const
161 reference
elementAt (std::ptrdiff_t offset)
const
167 reference dereference ()
const
172 void advance(std::ptrdiff_t d)
177 const B* p =
nullptr;
182 typedef RealIterator<B> iterator;
188 return iterator(p,p);
194 return iterator(p,p+n);
199 iterator beforeEnd ()
201 return iterator(p,p+n-1);
206 iterator beforeBegin ()
208 return iterator(p,p-1);
212 iterator find (size_type i)
218 typedef RealIterator<const B> const_iterator;
221 const_iterator begin ()
const
223 return const_iterator(p,p+0);
227 const_iterator end ()
const
229 return const_iterator(p,p+n);
234 const_iterator beforeEnd ()
const
236 return const_iterator(p,p+n-1);
241 const_iterator beforeBegin ()
const
243 return const_iterator(p,p-1);
247 const_iterator find (size_type i)
const
249 return const_iterator(p,p+
std::min(i,n));
256 size_type
size ()
const
262 const B* data()
const
275 base_array_unmanaged ()
279 base_array_unmanaged (size_type n_, B* p_)
309 template<
class B,
class ST=std::
size_t >
310 class compressed_base_array_unmanaged
317 typedef B member_type;
320 typedef ST size_type;
323 using reference = B&;
326 using const_reference =
const B&;
331 reference operator[] (size_type i)
333 const size_type* lb = std::lower_bound(j, j+n, i);
334 if (lb == j+n || *lb != i)
335 DUNE_THROW(ISTLError,
"index "<<i<<
" not in compressed array");
340 const_reference operator[] (size_type i)
const
342 const size_type* lb = std::lower_bound(j, j+n, i);
343 if (lb == j+n || *lb != i)
344 DUNE_THROW(ISTLError,
"index "<<i<<
" not in compressed array");
351 :
public BidirectionalIteratorFacade<RealIterator<T>, T>
355 typedef typename std::remove_const<T>::type ValueType;
357 friend class BidirectionalIteratorFacade<RealIterator<const ValueType>, const ValueType>;
358 friend class BidirectionalIteratorFacade<RealIterator<ValueType>, ValueType>;
359 friend class RealIterator<const ValueType>;
360 friend class RealIterator<ValueType>;
363 RealIterator () =
default;
366 RealIterator (B* _p, size_type* _j, size_type _i)
367 : p(_p), j(_j), i(_i)
371 std::enable_if_t<std::is_same_v<std::remove_const_t<T>, std::remove_const_t<T_>>,
int> = 0>
372 RealIterator (
const RealIterator<T_>& other)
373 : p(other.p), j(other.j), i(other.i)
377 std::enable_if_t<std::is_same_v<std::remove_const_t<T>, std::remove_const_t<T_>>,
int> = 0>
378 RealIterator& operator= (
const RealIterator<T_>& other)
388 bool equals (
const RealIterator<ValueType>& it)
const
395 bool equals (
const RealIterator<const ValueType>& it)
const
403 size_type index ()
const
409 void setindex (size_type k)
421 size_type offset ()
const
440 reference dereference ()
const
446 size_type* j =
nullptr;
451 typedef RealIterator<B> iterator;
456 return iterator(p,j,0);
462 return iterator(p,j,n);
467 iterator beforeEnd ()
469 return iterator(p,j,n-1);
474 iterator beforeBegin ()
476 return iterator(p,j,-1);
480 iterator find (size_type i)
482 const size_type* lb = std::lower_bound(j, j+n, i);
483 return (lb != j+n && *lb == i)
489 typedef RealIterator<const B> const_iterator;
492 const_iterator begin ()
const
494 return const_iterator(p,j,0);
498 const_iterator end ()
const
500 return const_iterator(p,j,n);
505 const_iterator beforeEnd ()
const
507 return const_iterator(p,j,n-1);
512 const_iterator beforeBegin ()
const
514 return const_iterator(p,j,-1);
518 const_iterator find (size_type i)
const
520 const size_type* lb = std::lower_bound(j, j+n, i);
521 return (lb != j+n && *lb == i)
522 ? const_iterator(p,j,lb-j)
529 size_type
size ()
const
536 compressed_base_array_unmanaged ()
#define DUNE_THROW(E,...)
Definition: exceptions.hh:312
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:587
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:506
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:126
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75