Reference documentation for deal.II version 9.4.1
\(\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\}}\)
Loading...
Searching...
No Matches
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
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
171 using size_type = typename value_type::size_type;
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 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
311protected:
312 /*
313 * The inheriting class should have a default constructor.
314 */
315 LinearIndexIterator() = default; // NOLINT
316
320 LinearIndexIterator(const AccessorType accessor);
321
322protected:
326 AccessorType accessor;
327};
328
329
330
331template <class DerivedIterator, class AccessorType>
332inline 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
343template <class DerivedIterator, class AccessorType>
344inline DerivedIterator &
346{
347 return operator+=(1);
348}
349
350
351
352template <class DerivedIterator, class AccessorType>
353inline DerivedIterator
355{
356 const DerivedIterator copy(this->accessor);
357 operator+=(1);
358 return copy;
359}
360
361
362
363template <class DerivedIterator, class AccessorType>
364inline DerivedIterator &
366{
367 return operator+=(-1);
368}
369
370
371
372template <class DerivedIterator, class AccessorType>
373inline DerivedIterator
375{
376 const DerivedIterator copy(this->accessor);
377 operator+=(-1);
378 return copy;
379}
380
381
382
383template <class DerivedIterator, class AccessorType>
384inline DerivedIterator
386 const difference_type n) const
387{
388 DerivedIterator copy(this->accessor);
389 copy += n;
390 return copy;
391}
392
393
394
395template <class DerivedIterator, class AccessorType>
396inline DerivedIterator
398 const difference_type n) const
399{
400 DerivedIterator copy(this->accessor);
401 copy += -n;
402 return copy;
403}
404
405
406
407template <class DerivedIterator, class AccessorType>
408inline DerivedIterator &
410 const difference_type n)
411{
412 accessor.linear_index += n;
413 return static_cast<DerivedIterator &>(*this);
414}
415
416
417
418template <class DerivedIterator, class AccessorType>
419inline DerivedIterator &
421 const difference_type n)
422{
423 return operator+=(-n);
424}
425
426
427
428template <class DerivedIterator, class AccessorType>
429inline
432 const DerivedIterator &other) const
433{
434 Assert(this->accessor.container == other.accessor.container,
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
442template <class DerivedIterator, class AccessorType>
445{
446 return accessor;
447}
448
449
450
451template <class DerivedIterator, class AccessorType>
454{
455 return &accessor;
456}
457
458
459
460template <class DerivedIterator, class AccessorType>
461inline bool
463 const DerivedIterator &other) const
464{
465 return (*this == other) || (*this < other);
466}
467
468
469
470template <class DerivedIterator, class AccessorType>
471inline bool
473 const DerivedIterator &other) const
474{
475 return !(*this < other);
476}
477
478
479
480template <class DerivedIterator, class AccessorType>
481inline bool
483 const DerivedIterator &other) const
484{
485 Assert(this->accessor.container == other.accessor.container,
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
493template <class DerivedIterator, class AccessorType>
494inline bool
496 const DerivedIterator &other) const
497{
498 return other < static_cast<const DerivedIterator &>(*this);
499}
500
501
502
503template <class DerivedIterator, class AccessorType>
505 const AccessorType accessor)
506 : accessor(accessor)
507{}
508
509
511
512#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:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
#define Assert(cond, exc)
Definition: exceptions.h:1473
static ::ExceptionBase & ExcMessage(std::string arg1)