Reference documentation for deal.II version 9.5.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
linear_index_iterator.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2018 - 2023 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_linear_index_iterator_h
17#define dealii_linear_index_iterator_h
18
19#include <deal.II/base/config.h>
20
22
23
138template <class DerivedIterator, class AccessorType>
140{
141public:
145#ifdef DEAL_II_HAVE_CXX20
146 using iterator_category = std::contiguous_iterator_tag;
147#else
148 using iterator_category = std::random_access_iterator_tag;
149#endif
150
155 using value_type = AccessorType;
156
160 using difference_type = std::ptrdiff_t;
161
165 using reference = const value_type &;
166
170 using pointer = const value_type *;
171
175 using size_type = typename value_type::size_type;
176
180 DerivedIterator &
181 operator=(const DerivedIterator &it);
182
186 DerivedIterator &
188
192 DerivedIterator
194
198 DerivedIterator &
200
204 DerivedIterator
206
210 DerivedIterator
212
216 DerivedIterator
218
222 DerivedIterator &
224
228 DerivedIterator &
230
238 operator-(const DerivedIterator &p) const;
239
244 operator*() const;
245
249 pointer
250 operator->() const;
251
256 template <typename OtherIterator>
257 friend std::enable_if_t<
258 std::is_convertible<OtherIterator, DerivedIterator>::value,
259 bool>
260 operator==(const LinearIndexIterator &left, const OtherIterator &right)
261 {
262 const auto &right_2 = static_cast<const DerivedIterator &>(right);
263 return left.accessor == right_2.accessor;
264 }
265
269 template <typename OtherIterator>
270 friend std::enable_if_t<
271 std::is_convertible<OtherIterator, DerivedIterator>::value,
272 bool>
273 operator!=(const LinearIndexIterator &left, const OtherIterator &right)
274 {
275 return !(left == right);
276 }
277
285 bool
286 operator<=(const DerivedIterator &) const;
287
295 bool
296 operator>=(const DerivedIterator &) const;
297
305 bool
306 operator<(const DerivedIterator &) const;
307
312 bool
313 operator>(const DerivedIterator &) const;
314
315protected:
316 /*
317 * The inheriting class should have a default constructor.
318 */
319 LinearIndexIterator() = default; // NOLINT
320
324 LinearIndexIterator(const AccessorType accessor);
325
326protected:
330 AccessorType accessor;
331};
332
333
334
335template <class DerivedIterator, class AccessorType>
336inline DerivedIterator &
338 const DerivedIterator &it)
339{
340 accessor.container = it.container;
341 accessor.linear_index = it.linear_index;
342 return static_cast<DerivedIterator &>(*this);
343}
344
345
346
347template <class DerivedIterator, class AccessorType>
348inline DerivedIterator &
350{
351 return operator+=(1);
352}
353
354
355
356template <class DerivedIterator, class AccessorType>
357inline DerivedIterator
359{
360 const DerivedIterator copy(this->accessor);
361 operator+=(1);
362 return copy;
363}
364
365
366
367template <class DerivedIterator, class AccessorType>
368inline DerivedIterator &
370{
371 return operator+=(-1);
372}
373
374
375
376template <class DerivedIterator, class AccessorType>
377inline DerivedIterator
379{
380 const DerivedIterator copy(this->accessor);
381 operator+=(-1);
382 return copy;
383}
384
385
386
387template <class DerivedIterator, class AccessorType>
388inline DerivedIterator
390 const difference_type n) const
391{
392 DerivedIterator copy(this->accessor);
393 copy += n;
394 return copy;
395}
396
397
398
399template <class DerivedIterator, class AccessorType>
400inline DerivedIterator
402 const difference_type n) const
403{
404 DerivedIterator copy(this->accessor);
405 copy += -n;
406 return copy;
407}
408
409
410
411template <class DerivedIterator, class AccessorType>
412inline DerivedIterator &
414 const difference_type n)
415{
416 accessor.linear_index += n;
417 return static_cast<DerivedIterator &>(*this);
418}
419
420
421
422template <class DerivedIterator, class AccessorType>
423inline DerivedIterator &
425 const difference_type n)
426{
427 return operator+=(-n);
428}
429
430
431
432template <class DerivedIterator, class AccessorType>
433inline
436 const DerivedIterator &other) const
437{
438 Assert(this->accessor.container == other.accessor.container,
440 "Only iterators pointing to the same container can be compared."));
441 return this->accessor.linear_index - other.accessor.linear_index;
442}
443
444
445
446template <class DerivedIterator, class AccessorType>
449{
450 return accessor;
451}
452
453
454
455template <class DerivedIterator, class AccessorType>
458{
459 return &accessor;
460}
461
462
463
464template <class DerivedIterator, class AccessorType>
465inline bool
467 const DerivedIterator &other) const
468{
469 return (*this == other) || (*this < other);
470}
471
472
473
474template <class DerivedIterator, class AccessorType>
475inline bool
477 const DerivedIterator &other) const
478{
479 return !(*this < other);
480}
481
482
483
484template <class DerivedIterator, class AccessorType>
485inline bool
487 const DerivedIterator &other) const
488{
489 Assert(this->accessor.container == other.accessor.container,
491 "Only iterators pointing to the same container can be compared."));
492 return this->accessor.linear_index < other.accessor.linear_index;
493}
494
495
496
497template <class DerivedIterator, class AccessorType>
498inline bool
500 const DerivedIterator &other) const
501{
502 return other < static_cast<const DerivedIterator &>(*this);
503}
504
505
506
507template <class DerivedIterator, class AccessorType>
509 const AccessorType accessor)
510 : accessor(accessor)
511{}
512
513
515
516#endif
reference operator*() const
LinearIndexIterator(const AccessorType accessor)
bool operator>=(const DerivedIterator &) const
friend std::enable_if_t< std::is_convertible< OtherIterator, DerivedIterator >::value, bool > operator==(const LinearIndexIterator &left, const OtherIterator &right)
friend std::enable_if_t< std::is_convertible< OtherIterator, DerivedIterator >::value, bool > operator!=(const LinearIndexIterator &left, const OtherIterator &right)
difference_type operator-(const DerivedIterator &p) const
bool operator<=(const DerivedIterator &) const
DerivedIterator & operator++()
DerivedIterator operator--(int)
DerivedIterator operator++(int)
bool operator>(const DerivedIterator &) const
const value_type * pointer
LinearIndexIterator()=default
DerivedIterator operator-(const difference_type n) const
std::random_access_iterator_tag iterator_category
typename value_type::size_type size_type
bool operator<(const DerivedIterator &) const
DerivedIterator operator+(const difference_type n) const
const value_type & reference
DerivedIterator & operator=(const DerivedIterator &it)
DerivedIterator & operator-=(const difference_type n)
DerivedIterator & operator--()
DerivedIterator & operator+=(const difference_type n)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)