libMesh
Loading...
Searching...
No Matches
int_range.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20#ifndef LIBMESH_INT_RANGE_H
21#define LIBMESH_INT_RANGE_H
22
23#include "libmesh/libmesh_common.h" // cast_int
24
25// C++ includes
26#include <vector>
27
28namespace libMesh
29{
30
31// Forward declarations
32template <typename T> class DenseSubVector;
33template <typename T> class DenseVector;
34template <typename T> class NumericVector;
35
52template <typename T>
54{
55public:
56 class iterator {
57 public:
58 using iterator_category = std::input_iterator_tag;
59 using value_type = T;
60 using difference_type = T;
61 using pointer = T;
62 using reference = T&;
63
64 explicit iterator (T i) : _i(i) {}
65
66 T operator* () const { return _i; }
67
69 {
70 ++_i;
71 return *this;
72 }
73
75 {
76 iterator returnval(*this);
77 ++_i;
78 return returnval;
79 }
80
81 template <typename T2>
82 void operator+= (T2 n)
83 {
84 _i += cast_int<T>(n);
85 }
86
87 template <typename T2>
88 iterator operator+ (T2 n) const
89 {
90 iterator returnval(_i);
91 returnval += n;
92 return returnval;
93 }
94
95 bool operator== (const iterator & j) const
96 {
97 return ( _i == j._i );
98 }
99
100 bool operator!= (const iterator & j) const
101 {
102 return !(*this == j);
103 }
104
105 private:
106 T _i;
107 };
108
110
111 template <typename U, typename V>
113 _begin(cast_int<T>(begin)),
114 _end(cast_int<T>(end))
115 {}
116
117 // Signature needed for use in threads_pthread.h
119 const const_iterator & begin,
120 const const_iterator & end) :
121 _begin(begin),
122 _end(end)
123 {}
124
125 iterator begin() const { return _begin; }
126
127 iterator end () const { return _end; }
128
129 std::size_t size () const
130 { return *_end - *_begin; }
131
132 // For thread splitting control
133 std::size_t grainsize () const { return libMesh::default_grainsize(); }
134
135private:
137};
138
139
140template <typename T, typename T2>
142{
143 return i + n;
144}
145
146
152template <typename T>
153auto index_range(const T & sizable)
154{
155 return IntRange<decltype(sizable.size())>(0, sizable.size());
156}
157
158
162template <typename T>
167
168
169
175template <typename T>
177{
178 return {beg, end};
179}
180
181
182
196template <typename T>
198{
199 return {T(0), end};
200}
201
202} // namespace libMesh
203
204#endif // LIBMESH_INT_RANGE_H
bool operator!=(const iterator &j) const
Definition int_range.h:100
bool operator==(const iterator &j) const
Definition int_range.h:95
const iterator & operator++()
Definition int_range.h:68
std::input_iterator_tag iterator_category
Definition int_range.h:58
iterator operator+(T2 n) const
Definition int_range.h:88
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
Definition int_range.h:54
IntRange(const IntRange &, const const_iterator &begin, const const_iterator &end)
Definition int_range.h:118
IntRange< T >::iterator const_iterator
Definition int_range.h:109
iterator begin() const
Definition int_range.h:125
std::size_t size() const
Definition int_range.h:129
IntRange(U begin, V end)
Definition int_range.h:112
iterator end() const
Definition int_range.h:127
std::size_t grainsize() const
Definition int_range.h:133
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual numeric_index_type last_local_index() const =0
virtual numeric_index_type first_local_index() const =0
The libMesh namespace provides an interface to certain functionality in the library.
unsigned int default_grainsize()
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
Order operator+(Order o, T p)
Definition enum_order.h:93
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176