omega_h
Reliable mesh adaptation
Omega_h_int_iterator.hpp
1 #ifndef OMEGA_H_INT_ITERATOR_HPP
2 #define OMEGA_H_INT_ITERATOR_HPP
3 
4 #include <Omega_h_defines.hpp>
5 #include <iterator>
6 
7 namespace Omega_h {
8 
9 class IntIterator {
10  LO i;
11 
12  public:
13  using value_type = LO;
14  using difference_type = LO;
15  using reference = LO const&;
16  using pointer = LO const*;
17  using iterator_category = std::random_access_iterator_tag;
18  inline IntIterator() noexcept = default;
19  OMEGA_H_INLINE IntIterator(LO i_in) noexcept : i(i_in) {}
20  OMEGA_H_INLINE bool operator==(IntIterator const& other) const noexcept {
21  return i == other.i;
22  }
23  OMEGA_H_INLINE bool operator!=(IntIterator const& other) const noexcept {
24  return i != other.i;
25  }
26  OMEGA_H_INLINE reference operator*() const noexcept { return i; }
27  OMEGA_H_INLINE pointer operator->() const noexcept { return &i; }
28  OMEGA_H_INLINE IntIterator& operator++() noexcept {
29  ++i;
30  return *this;
31  }
32  OMEGA_H_INLINE IntIterator operator++(int) noexcept {
33  auto ret = *this;
34  ++i;
35  return ret;
36  }
37  OMEGA_H_INLINE IntIterator& operator--() noexcept {
38  --i;
39  return *this;
40  }
41  OMEGA_H_INLINE IntIterator operator--(int) noexcept {
42  auto ret = *this;
43  --i;
44  return ret;
45  }
46  OMEGA_H_INLINE IntIterator& operator+=(difference_type n) noexcept {
47  i += n;
48  return *this;
49  }
50  OMEGA_H_INLINE IntIterator& operator-=(difference_type n) noexcept {
51  i -= n;
52  return *this;
53  }
54  OMEGA_H_INLINE IntIterator operator+(difference_type n) const noexcept {
55  return IntIterator(i + n);
56  }
57  OMEGA_H_INLINE IntIterator operator-(difference_type n) const noexcept {
58  return IntIterator(i - n);
59  }
60  OMEGA_H_INLINE difference_type operator-(IntIterator const& other) const
61  noexcept {
62  return i - other.i;
63  }
64  OMEGA_H_INLINE value_type operator[](difference_type n) const noexcept {
65  return i + n;
66  }
67  OMEGA_H_INLINE bool operator<(IntIterator const& other) const noexcept {
68  return i < other.i;
69  }
70  OMEGA_H_INLINE bool operator>(IntIterator const& other) const noexcept {
71  return i > other.i;
72  }
73  OMEGA_H_INLINE bool operator<=(IntIterator const& other) const noexcept {
74  return i <= other.i;
75  }
76  OMEGA_H_INLINE bool operator>=(IntIterator const& other) const noexcept {
77  return i >= other.i;
78  }
79 };
80 
81 OMEGA_H_INLINE IntIterator operator+(
82  IntIterator::difference_type n, IntIterator it) noexcept {
83  return it + n;
84 }
85 
86 } // namespace Omega_h
87 
88 #endif
Definition: Omega_h_int_iterator.hpp:9
Definition: amr_mpi_test.cpp:6