Reference documentation for deal.II version Git 50c3491829 2021-08-01 13:40:40 +0200
\(\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 - 2020 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 &
183  operator++();
184 
188  DerivedIterator
189  operator++(int);
190 
194  DerivedIterator &
195  operator--();
196 
200  DerivedIterator
201  operator--(int);
202 
206  DerivedIterator
207  operator+(const difference_type n) const;
208 
212  DerivedIterator
213  operator-(const difference_type n) const;
214 
218  DerivedIterator &
219  operator+=(const difference_type n);
220 
224  DerivedIterator &
225  operator-=(const difference_type n);
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 typename std::enable_if<
254  std::is_convertible<OtherIterator, DerivedIterator>::value,
255  bool>::type
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 typename std::enable_if<
267  std::is_convertible<OtherIterator, DerivedIterator>::value,
268  bool>::type
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
DerivedIterator & operator+=(const difference_type n)
types::global_dof_index size_type
Definition: cuda_kernels.h:45
bool operator<(const DerivedIterator &) const
friend std::enable_if< std::is_convertible< OtherIterator, DerivedIterator >::value, bool >::type operator==(const LinearIndexIterator &left, const OtherIterator &right)
DerivedIterator operator-(const difference_type n) const
DerivedIterator & operator=(const DerivedIterator &it)
LinearIndexIterator()=default
static ::ExceptionBase & ExcMessage(std::string arg1)
DerivedIterator operator+(const difference_type n) const
bool operator>(const DerivedIterator &) const
bool operator<=(const DerivedIterator &) const
#define Assert(cond, exc)
Definition: exceptions.h:1467
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:401
std::random_access_iterator_tag iterator_category
DerivedIterator & operator++()
bool operator>=(const DerivedIterator &) const
DerivedIterator & operator-=(const difference_type n)
DerivedIterator & operator--()
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:400
friend std::enable_if< std::is_convertible< OtherIterator, DerivedIterator >::value, bool >::type operator!=(const LinearIndexIterator &left, const OtherIterator &right)
void copy(const T *begin, const T *end, U *dest)
reference operator*() const