Reference documentation for deal.II version GIT 741a3088b8 2023-04-01 07:05: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 - 2021 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 <class DerivedIterator, class AccessorType>
140 {
141 public:
145  using iterator_category = std::random_access_iterator_tag;
146 
151  using value_type = AccessorType;
152 
156  using difference_type = std::ptrdiff_t;
157 
161  using reference = const value_type &;
162 
166  using pointer = const value_type *;
167 
172 
176  DerivedIterator &
177  operator=(const DerivedIterator &it);
178 
182  DerivedIterator &
184 
188  DerivedIterator
190 
194  DerivedIterator &
196 
200  DerivedIterator
202 
206  DerivedIterator
207  operator+(const difference_type n) const;
208 
212  DerivedIterator
213  operator-(const difference_type n) const;
214 
218  DerivedIterator &
220 
224  DerivedIterator &
226 
234  operator-(const DerivedIterator &p) const;
235 
239  reference
240  operator*() const;
241 
245  pointer
246  operator->() const;
247 
252  template <typename OtherIterator>
253  friend std::enable_if_t<
254  std::is_convertible<OtherIterator, DerivedIterator>::value,
255  bool>
256  operator==(const LinearIndexIterator &left, const OtherIterator &right)
257  {
258  const auto &right_2 = static_cast<const DerivedIterator &>(right);
259  return left.accessor == right_2.accessor;
260  }
261 
265  template <typename OtherIterator>
266  friend std::enable_if_t<
267  std::is_convertible<OtherIterator, DerivedIterator>::value,
268  bool>
269  operator!=(const LinearIndexIterator &left, const OtherIterator &right)
270  {
271  return !(left == 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 <class DerivedIterator, class 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 <class DerivedIterator, class AccessorType>
344 inline DerivedIterator &
346 {
347  return operator+=(1);
348 }
349 
350 
351 
352 template <class DerivedIterator, class AccessorType>
353 inline DerivedIterator
355 {
356  const DerivedIterator copy(this->accessor);
357  operator+=(1);
358  return copy;
359 }
360 
361 
362 
363 template <class DerivedIterator, class AccessorType>
364 inline DerivedIterator &
366 {
367  return operator+=(-1);
368 }
369 
370 
371 
372 template <class DerivedIterator, class AccessorType>
373 inline DerivedIterator
375 {
376  const DerivedIterator copy(this->accessor);
377  operator+=(-1);
378  return copy;
379 }
380 
381 
382 
383 template <class DerivedIterator, class 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 <class DerivedIterator, class 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 <class DerivedIterator, class 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 <class DerivedIterator, class AccessorType>
419 inline DerivedIterator &
421  const difference_type n)
422 {
423  return operator+=(-n);
424 }
425 
426 
427 
428 template <class DerivedIterator, class 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 <class DerivedIterator, class AccessorType>
445 {
446  return accessor;
447 }
448 
449 
450 
451 template <class DerivedIterator, class AccessorType>
454 {
455  return &accessor;
456 }
457 
458 
459 
460 template <class DerivedIterator, class AccessorType>
461 inline bool
463  const DerivedIterator &other) const
464 {
465  return (*this == other) || (*this < other);
466 }
467 
468 
469 
470 template <class DerivedIterator, class AccessorType>
471 inline bool
473  const DerivedIterator &other) const
474 {
475  return !(*this < other);
476 }
477 
478 
479 
480 template <class DerivedIterator, class 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 <class DerivedIterator, class AccessorType>
494 inline bool
496  const DerivedIterator &other) const
497 {
498  return other < static_cast<const DerivedIterator &>(*this);
499 }
500 
501 
502 
503 template <class DerivedIterator, class AccessorType>
505  const AccessorType accessor)
506  : accessor(accessor)
507 {}
508 
509 
511 
512 #endif
reference operator*() const
LinearIndexIterator(const AccessorType accessor)
friend std::enable_if_t< std::is_convertible< OtherIterator, DerivedIterator >::value, bool > operator!=(const LinearIndexIterator &left, const OtherIterator &right)
bool operator>=(const DerivedIterator &) const
difference_type operator-(const DerivedIterator &p) const
bool operator<=(const DerivedIterator &) const
DerivedIterator & operator++()
DerivedIterator operator--(int)
friend std::enable_if_t< std::is_convertible< OtherIterator, DerivedIterator >::value, bool > operator==(const LinearIndexIterator &left, const OtherIterator &right)
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:474
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:475
#define Assert(cond, exc)
Definition: exceptions.h:1586
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)