Reference documentation for deal.II version Git ce7b8fd3ef 2020-09-19 21:33:14 +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 - 2019 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 operator*() const;
240 
244  pointer operator->() const;
245 
250  template <typename OtherIterator>
251  friend typename std::enable_if<
252  std::is_convertible<OtherIterator, DerivedIterator>::value,
253  bool>::type
254  operator==(const LinearIndexIterator &left, const OtherIterator &right)
255  {
256  const auto &right_2 = static_cast<const DerivedIterator &>(right);
257  return left.accessor == right_2.accessor;
258  }
259 
263  template <typename OtherIterator>
264  friend typename std::enable_if<
265  std::is_convertible<OtherIterator, DerivedIterator>::value,
266  bool>::type
267  operator!=(const LinearIndexIterator &left, const OtherIterator &right)
268  {
269  return !(left == right);
270  }
271 
279  bool
280  operator<=(const DerivedIterator &) const;
281 
289  bool
290  operator>=(const DerivedIterator &) const;
291 
299  bool
300  operator<(const DerivedIterator &) const;
301 
306  bool
307  operator>(const DerivedIterator &) const;
308 
309 protected:
310  /*
311  * The inheriting class should have a default constructor.
312  */
313  LinearIndexIterator() = default; // NOLINT
314 
318  LinearIndexIterator(const AccessorType accessor);
319 
320 protected:
324  AccessorType accessor;
325 };
326 
327 
328 
329 template <class DerivedIterator, class AccessorType>
330 inline DerivedIterator &
332 operator=(const DerivedIterator &it)
333 {
334  accessor.container = it.container;
335  accessor.linear_index = it.linear_index;
336  return static_cast<DerivedIterator &>(*this);
337 }
338 
339 
340 
341 template <class DerivedIterator, class AccessorType>
342 inline DerivedIterator &
344 {
345  return operator+=(1);
346 }
347 
348 
349 
350 template <class DerivedIterator, class AccessorType>
351 inline DerivedIterator
353 {
354  const DerivedIterator copy(this->accessor);
355  operator+=(1);
356  return copy;
357 }
358 
359 
360 
361 template <class DerivedIterator, class AccessorType>
362 inline DerivedIterator &
364 {
365  return operator+=(-1);
366 }
367 
368 
369 
370 template <class DerivedIterator, class AccessorType>
371 inline DerivedIterator
373 {
374  const DerivedIterator copy(this->accessor);
375  operator+=(-1);
376  return copy;
377 }
378 
379 
380 
381 template <class DerivedIterator, class AccessorType>
382 inline DerivedIterator
385 {
386  DerivedIterator copy(this->accessor);
387  copy += n;
388  return copy;
389 }
390 
391 
392 
393 template <class DerivedIterator, class AccessorType>
394 inline DerivedIterator
397 {
398  DerivedIterator copy(this->accessor);
399  copy += -n;
400  return copy;
401 }
402 
403 
404 
405 template <class DerivedIterator, class AccessorType>
406 inline DerivedIterator &
409 {
410  accessor.linear_index += n;
411  return static_cast<DerivedIterator &>(*this);
412 }
413 
414 
415 
416 template <class DerivedIterator, class AccessorType>
417 inline DerivedIterator &
420 {
421  return operator+=(-n);
422 }
423 
424 
425 
426 template <class DerivedIterator, class AccessorType>
427 inline
430  operator-(const DerivedIterator &other) const
431 {
432  Assert(this->accessor.container == other.accessor.container,
433  ExcMessage(
434  "Only iterators pointing to the same container can be compared."));
435  return this->accessor.linear_index - other.accessor.linear_index;
436 }
437 
438 
439 
440 template <class DerivedIterator, class AccessorType>
443 {
444  return accessor;
445 }
446 
447 
448 
449 template <class DerivedIterator, class AccessorType>
452 {
453  return &accessor;
454 }
455 
456 
457 
458 template <class DerivedIterator, class AccessorType>
459 inline bool
461 operator<=(const DerivedIterator &other) const
462 {
463  return (*this == other) || (*this < other);
464 }
465 
466 
467 
468 template <class DerivedIterator, class AccessorType>
469 inline bool
471 operator>=(const DerivedIterator &other) const
472 {
473  return !(*this < other);
474 }
475 
476 
477 
478 template <class DerivedIterator, class AccessorType>
479 inline bool
481 operator<(const DerivedIterator &other) const
482 {
483  Assert(this->accessor.container == other.accessor.container,
484  ExcMessage(
485  "Only iterators pointing to the same container can be compared."));
486  return this->accessor.linear_index < other.accessor.linear_index;
487 }
488 
489 
490 
491 template <class DerivedIterator, class AccessorType>
492 inline bool
494 operator>(const DerivedIterator &other) const
495 {
496  return other < static_cast<const DerivedIterator &>(*this);
497 }
498 
499 
500 
501 template <class DerivedIterator, class AccessorType>
503  const AccessorType accessor)
504  : accessor(accessor)
505 {}
506 
507 
509 
510 #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:1411
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
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:362
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