Reference documentation for deal.II version 9.3.3
\(\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
138template <class DerivedIterator, class AccessorType>
140{
141public:
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
208
212 DerivedIterator
214
218 DerivedIterator &
220
224 DerivedIterator &
226
234 operator-(const DerivedIterator &p) const;
235
240
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
309protected:
310 /*
311 * The inheriting class should have a default constructor.
312 */
313 LinearIndexIterator() = default; // NOLINT
314
318 LinearIndexIterator(const AccessorType accessor);
319
320protected:
324 AccessorType accessor;
325};
326
327
328
329template <class DerivedIterator, class AccessorType>
330inline DerivedIterator &
332operator=(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
341template <class DerivedIterator, class AccessorType>
342inline DerivedIterator &
344{
345 return operator+=(1);
346}
347
348
349
350template <class DerivedIterator, class AccessorType>
351inline DerivedIterator
353{
354 const DerivedIterator copy(this->accessor);
355 operator+=(1);
356 return copy;
357}
358
359
360
361template <class DerivedIterator, class AccessorType>
362inline DerivedIterator &
364{
365 return operator+=(-1);
366}
367
368
369
370template <class DerivedIterator, class AccessorType>
371inline DerivedIterator
373{
374 const DerivedIterator copy(this->accessor);
375 operator+=(-1);
376 return copy;
377}
378
379
380
381template <class DerivedIterator, class AccessorType>
382inline DerivedIterator
384operator+(const difference_type n) const
385{
386 DerivedIterator copy(this->accessor);
387 copy += n;
388 return copy;
389}
390
391
392
393template <class DerivedIterator, class AccessorType>
394inline DerivedIterator
396operator-(const difference_type n) const
397{
398 DerivedIterator copy(this->accessor);
399 copy += -n;
400 return copy;
401}
402
403
404
405template <class DerivedIterator, class AccessorType>
406inline DerivedIterator &
409{
410 accessor.linear_index += n;
411 return static_cast<DerivedIterator &>(*this);
412}
413
414
415
416template <class DerivedIterator, class AccessorType>
417inline DerivedIterator &
420{
421 return operator+=(-n);
422}
423
424
425
426template <class DerivedIterator, class AccessorType>
427inline
430 operator-(const DerivedIterator &other) const
431{
432 Assert(this->accessor.container == other.accessor.container,
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
440template <class DerivedIterator, class AccessorType>
443{
444 return accessor;
445}
446
447
448
449template <class DerivedIterator, class AccessorType>
452{
453 return &accessor;
454}
455
456
457
458template <class DerivedIterator, class AccessorType>
459inline bool
461operator<=(const DerivedIterator &other) const
462{
463 return (*this == other) || (*this < other);
464}
465
466
467
468template <class DerivedIterator, class AccessorType>
469inline bool
471operator>=(const DerivedIterator &other) const
472{
473 return !(*this < other);
474}
475
476
477
478template <class DerivedIterator, class AccessorType>
479inline bool
481operator<(const DerivedIterator &other) const
482{
483 Assert(this->accessor.container == other.accessor.container,
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
491template <class DerivedIterator, class AccessorType>
492inline bool
494operator>(const DerivedIterator &other) const
495{
496 return other < static_cast<const DerivedIterator &>(*this);
497}
498
499
500
501template <class DerivedIterator, class AccessorType>
503 const AccessorType accessor)
504 : accessor(accessor)
505{}
506
507
509
510#endif
reference operator*() const
LinearIndexIterator(const AccessorType accessor)
bool operator>=(const DerivedIterator &) const
difference_type operator-(const DerivedIterator &p) const
friend std::enable_if< std::is_convertible< OtherIterator, DerivedIterator >::value, bool >::type operator!=(const LinearIndexIterator &left, const OtherIterator &right)
bool operator<=(const DerivedIterator &) const
DerivedIterator & operator++()
DerivedIterator operator--(int)
DerivedIterator operator++(int)
friend std::enable_if< std::is_convertible< OtherIterator, DerivedIterator >::value, bool >::type operator==(const LinearIndexIterator &left, const OtherIterator &right)
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:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
#define Assert(cond, exc)
Definition: exceptions.h:1465
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)