Reference documentation for deal.II version GIT c14369f203 2023-10-01 07:40:02+00:00
\(\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\}}\)
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 
138 template <typename DerivedIterator, typename AccessorType>
140 {
141 public:
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 
176 
180  DerivedIterator &
181  operator=(const DerivedIterator &it);
182 
186  DerivedIterator &
188 
192  DerivedIterator
194 
198  DerivedIterator &
200 
204  DerivedIterator
206 
210  DerivedIterator
211  operator+(const difference_type n) const;
212 
216  DerivedIterator
217  operator-(const difference_type n) const;
218 
222  DerivedIterator &
224 
228  DerivedIterator &
230 
238  operator-(const DerivedIterator &p) const;
239 
243  reference
244  operator*() const;
245 
249  pointer
250  operator->() const;
251 
256  template <typename OtherIterator>
257  std::enable_if_t<std::is_convertible_v<OtherIterator, DerivedIterator>, bool>
258  operator==(const OtherIterator &right) const
259  {
260  const auto &right_2 = static_cast<const DerivedIterator &>(right);
261  return this->accessor == right_2.accessor;
262  }
263 
267  template <typename OtherIterator>
268  std::enable_if_t<std::is_convertible_v<OtherIterator, DerivedIterator>, bool>
269  operator!=(const OtherIterator &right) const
270  {
271  return !(*this == right);
272  }
273 
281  bool
282  operator<=(const DerivedIterator &) const;
283 
291  bool
292  operator>=(const DerivedIterator &) const;
293 
301  bool
302  operator<(const DerivedIterator &) const;
303 
308  bool
309  operator>(const DerivedIterator &) const;
310 
311 protected:
312  /*
313  * The inheriting class should have a default constructor.
314  */
315  LinearIndexIterator() = default; // NOLINT
316 
320  LinearIndexIterator(const AccessorType accessor);
321 
322 protected:
326  AccessorType accessor;
327 };
328 
329 
330 
331 template <typename DerivedIterator, typename AccessorType>
332 inline DerivedIterator &
334  const DerivedIterator &it)
335 {
336  accessor.container = it.container;
337  accessor.linear_index = it.linear_index;
338  return static_cast<DerivedIterator &>(*this);
339 }
340 
341 
342 
343 template <typename DerivedIterator, typename AccessorType>
344 inline DerivedIterator &
346 {
347  return operator+=(1);
348 }
349 
350 
351 
352 template <typename DerivedIterator, typename AccessorType>
353 inline DerivedIterator
355 {
356  const DerivedIterator copy(this->accessor);
357  operator+=(1);
358  return copy;
359 }
360 
361 
362 
363 template <typename DerivedIterator, typename AccessorType>
364 inline DerivedIterator &
366 {
367  return operator+=(-1);
368 }
369 
370 
371 
372 template <typename DerivedIterator, typename AccessorType>
373 inline DerivedIterator
375 {
376  const DerivedIterator copy(this->accessor);
377  operator+=(-1);
378  return copy;
379 }
380 
381 
382 
383 template <typename DerivedIterator, typename AccessorType>
384 inline DerivedIterator
386  const difference_type n) const
387 {
388  DerivedIterator copy(this->accessor);
389  copy += n;
390  return copy;
391 }
392 
393 
394 
395 template <typename DerivedIterator, typename AccessorType>
396 inline DerivedIterator
398  const difference_type n) const
399 {
400  DerivedIterator copy(this->accessor);
401  copy += -n;
402  return copy;
403 }
404 
405 
406 
407 template <typename DerivedIterator, typename AccessorType>
408 inline DerivedIterator &
410  const difference_type n)
411 {
412  accessor.linear_index += n;
413  return static_cast<DerivedIterator &>(*this);
414 }
415 
416 
417 
418 template <typename DerivedIterator, typename AccessorType>
419 inline DerivedIterator &
421  const difference_type n)
422 {
423  return operator+=(-n);
424 }
425 
426 
427 
428 template <typename DerivedIterator, typename AccessorType>
429 inline
432  const DerivedIterator &other) const
433 {
434  Assert(this->accessor.container == other.accessor.container,
435  ExcMessage(
436  "Only iterators pointing to the same container can be compared."));
437  return this->accessor.linear_index - other.accessor.linear_index;
438 }
439 
440 
441 
442 template <typename DerivedIterator, typename AccessorType>
445 {
446  return accessor;
447 }
448 
449 
450 
451 template <typename DerivedIterator, typename AccessorType>
454 {
455  return &accessor;
456 }
457 
458 
459 
460 template <typename DerivedIterator, typename AccessorType>
461 inline bool
463  const DerivedIterator &other) const
464 {
465  return (*this == other) || (*this < other);
466 }
467 
468 
469 
470 template <typename DerivedIterator, typename AccessorType>
471 inline bool
473  const DerivedIterator &other) const
474 {
475  return !(*this < other);
476 }
477 
478 
479 
480 template <typename DerivedIterator, typename AccessorType>
481 inline bool
483  const DerivedIterator &other) const
484 {
485  Assert(this->accessor.container == other.accessor.container,
486  ExcMessage(
487  "Only iterators pointing to the same container can be compared."));
488  return this->accessor.linear_index < other.accessor.linear_index;
489 }
490 
491 
492 
493 template <typename DerivedIterator, typename AccessorType>
494 inline bool
496  const DerivedIterator &other) const
497 {
498  return other < static_cast<const DerivedIterator &>(*this);
499 }
500 
501 
502 
503 template <typename DerivedIterator, typename AccessorType>
505  const AccessorType accessor)
506  : accessor(accessor)
507 {}
508 
509 
511 
512 #endif
std::enable_if_t< std::is_convertible_v< OtherIterator, DerivedIterator >, bool > operator==(const OtherIterator &right) const
reference operator*() const
std::enable_if_t< std::is_convertible_v< OtherIterator, DerivedIterator >, bool > operator!=(const OtherIterator &right) const
LinearIndexIterator(const AccessorType accessor)
bool operator>=(const DerivedIterator &) const
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
std::ptrdiff_t difference_type
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:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
#define Assert(cond, exc)
Definition: exceptions.h:1616
static ::ExceptionBase & ExcMessage(std::string arg1)
types::global_dof_index size_type
Definition: cuda_kernels.h:45
void copy(const T *begin, const T *end, U *dest)