deal.II version GIT relicensing-2167-g9622207b8f 2024-11-21 12:40:00+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\}}\)
Loading...
Searching...
No Matches
linear_index_iterator.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2018 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_linear_index_iterator_h
16#define dealii_linear_index_iterator_h
17
18#include <deal.II/base/config.h>
19
21
22
137template <typename DerivedIterator, typename AccessorType>
139{
140public:
144#ifdef DEAL_II_HAVE_CXX20
145 using iterator_category = std::contiguous_iterator_tag;
146#else
147 using iterator_category = std::random_access_iterator_tag;
148#endif
149
154 using value_type = AccessorType;
155
159 using difference_type = std::ptrdiff_t;
160
164 using reference = const value_type &;
165
169 using pointer = const value_type *;
170
174 using size_type = typename value_type::size_type;
175
179 DerivedIterator &
180 operator=(const DerivedIterator &it);
181
185 DerivedIterator &
187
191 DerivedIterator
193
197 DerivedIterator &
199
203 DerivedIterator
205
209 DerivedIterator
211
215 DerivedIterator
217
221 DerivedIterator &
223
227 DerivedIterator &
229
237 operator-(const DerivedIterator &p) const;
238
243 operator*() const;
244
248 pointer
249 operator->() const;
250
255 template <typename OtherIterator>
256 std::enable_if_t<std::is_convertible_v<OtherIterator, DerivedIterator>, bool>
257 operator==(const OtherIterator &right) const
258 {
259 const auto &right_2 = static_cast<const DerivedIterator &>(right);
260 return this->accessor == right_2.accessor;
261 }
262
266 template <typename OtherIterator>
267 std::enable_if_t<std::is_convertible_v<OtherIterator, DerivedIterator>, bool>
268 operator!=(const OtherIterator &right) const
269 {
270 return !(*this == right);
271 }
272
280 bool
281 operator<=(const DerivedIterator &) const;
282
290 bool
291 operator>=(const DerivedIterator &) const;
292
300 bool
301 operator<(const DerivedIterator &) const;
302
307 bool
308 operator>(const DerivedIterator &) const;
309
310protected:
311 /*
312 * The inheriting class should have a default constructor.
313 */
314 LinearIndexIterator() = default; // NOLINT
315
319 LinearIndexIterator(const AccessorType accessor);
320
321protected:
325 AccessorType accessor;
326};
327
328
329
330template <typename DerivedIterator, typename AccessorType>
331inline DerivedIterator &
333 const DerivedIterator &it)
334{
335 accessor.container = it.container;
336 accessor.linear_index = it.linear_index;
337 return static_cast<DerivedIterator &>(*this);
338}
339
340
341
342template <typename DerivedIterator, typename AccessorType>
343inline DerivedIterator &
348
349
350
351template <typename DerivedIterator, typename AccessorType>
352inline DerivedIterator
354{
355 const DerivedIterator copy(this->accessor);
356 operator+=(1);
357 return copy;
358}
359
360
361
362template <typename DerivedIterator, typename AccessorType>
363inline DerivedIterator &
368
369
370
371template <typename DerivedIterator, typename AccessorType>
372inline DerivedIterator
374{
375 const DerivedIterator copy(this->accessor);
376 operator+=(-1);
377 return copy;
378}
379
380
381
382template <typename DerivedIterator, typename AccessorType>
383inline DerivedIterator
385 const difference_type n) const
386{
387 DerivedIterator copy(this->accessor);
388 copy += n;
389 return copy;
390}
391
392
393
394template <typename DerivedIterator, typename AccessorType>
395inline DerivedIterator
397 const difference_type n) const
398{
399 DerivedIterator copy(this->accessor);
400 copy += -n;
401 return copy;
402}
403
404
405
406template <typename DerivedIterator, typename AccessorType>
407inline DerivedIterator &
409 const difference_type n)
410{
411 accessor.linear_index += n;
412 return static_cast<DerivedIterator &>(*this);
413}
414
415
416
417template <typename DerivedIterator, typename AccessorType>
418inline DerivedIterator &
424
425
426
427template <typename DerivedIterator, typename AccessorType>
428inline
431 const DerivedIterator &other) const
432{
433 Assert(this->accessor.container == other.accessor.container,
435 "Only iterators pointing to the same container can be compared."));
436 return this->accessor.linear_index - other.accessor.linear_index;
437}
438
439
440
441template <typename DerivedIterator, typename AccessorType>
447
448
449
450template <typename DerivedIterator, typename AccessorType>
456
457
458
459template <typename DerivedIterator, typename AccessorType>
460inline bool
462 const DerivedIterator &other) const
463{
464 return (*this == other) || (*this < other);
465}
466
467
468
469template <typename DerivedIterator, typename AccessorType>
470inline bool
472 const DerivedIterator &other) const
473{
474 return !(*this < other);
475}
476
477
478
479template <typename DerivedIterator, typename AccessorType>
480inline bool
482 const DerivedIterator &other) const
483{
484 Assert(this->accessor.container == other.accessor.container,
486 "Only iterators pointing to the same container can be compared."));
487 return this->accessor.linear_index < other.accessor.linear_index;
488}
489
490
491
492template <typename DerivedIterator, typename AccessorType>
493inline bool
495 const DerivedIterator &other) const
496{
497 return other < static_cast<const DerivedIterator &>(*this);
498}
499
500
501
502template <typename DerivedIterator, typename AccessorType>
504 const AccessorType accessor)
505 : accessor(accessor)
506{}
507
508
510
511#endif
reference operator*() const
std::enable_if_t< std::is_convertible_v< OtherIterator, DerivedIterator >, bool > operator!=(const OtherIterator &right) const
LinearIndexIterator(const AccessorType accessor)
std::enable_if_t< std::is_convertible_v< OtherIterator, DerivedIterator >, bool > operator==(const OtherIterator &right) const
bool operator>=(const DerivedIterator &) const
difference_type operator-(const DerivedIterator &p) const
bool operator<=(const DerivedIterator &) const
DerivedIterator & operator++()
DerivedIterator operator--(int)
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
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:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)