StrideRangeI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2025 OpenCFD Ltd.
9  Copyright (C) 2026 Keysight Technologies
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class IntType>
32 inline IntType
34 {
35  return (start_ + ((i < 0 || i > size_) ? size_ : i) * stride_);
36 }
37 
38 
39 template<class IntType>
40 template<class IntT2>
41 inline constexpr int Foam::StrideRange<IntType>::compare
42 (
43  const StrideRange<IntT2>& other
44 ) const noexcept
45 {
46  if (this->start() < other.start()) return -1;
47  if (other.start() < this->start()) return +1;
48 
49  if (this->size() < other.size()) return -1;
50  if (other.size() < this->size()) return +1;
51 
52  if (this->stride() < other.stride()) return -1;
53  if (other.stride() < this->stride()) return +1;
54 
55  return 0;
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
61 template<class IntType>
63 :
64  start_(0),
65  size_(0),
66  stride_(0)
67 {}
68 
69 
70 template<class IntType>
72 (
73  IntType beg,
74  IntType len,
75  IntType stride
76 ) noexcept
77 :
78  start_(beg),
79  size_(len),
80  stride_(stride)
81 {}
82 
83 
84 // template<class IntType>
85 // inline constexpr Foam::StrideRange<IntType>::StrideRange
86 // (
87 // IntType len,
88 // IntType stride
89 // ) noexcept
90 // :
91 // start_(0),
92 // size_(len),
93 // stride_(stride)
94 // {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
99 template<class IntType>
100 inline constexpr IntType
102 {
103  return (start_);
104 }
105 
106 
107 template<class IntType>
108 inline constexpr IntType
110 {
111  return (start_ + size_ * stride_);
112 }
113 
114 
115 template<class IntType>
116 inline constexpr IntType
118 {
119  return (start_ + (size_-1) * stride_);
120 }
121 
122 
123 template<class IntType>
124 inline constexpr IntType
126 {
127  return (start_ - stride_);
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
132 
133 template<class IntType>
134 inline constexpr IntType
136 {
137  return (start_ + i * stride_);
138 }
139 
140 
141 template<class IntType>
142 template<class IntT2>
143 inline constexpr bool Foam::StrideRange<IntType>::operator==
144 (
145  const StrideRange<IntT2>& other
146 ) const noexcept
147 {
148  return
149  (
150  this->start() == other.start()
151  && this->size() == other.size()
152  && this->stride() == other.stride()
153  );
154 }
155 
156 
157 // ************************************************************************* //
constexpr IntType rend_value() const noexcept
The value that is one stride before the begin of start/size range.
Definition: StrideRangeI.H:118
constexpr IntType begin_value() const noexcept
The value at the beginning of the range - same as start()
Definition: StrideRangeI.H:94
constexpr IntType end_value() const noexcept
The value that is one stride beyond the end of the range.
Definition: StrideRangeI.H:102
const direction noexcept
Definition: scalarImpl.H:265
constexpr IntType operator[](IntType i) const noexcept
Offset dereference, without bounds checking Return element in the range, without bounds checking...
Definition: StrideRangeI.H:128
constexpr StrideRange() noexcept
Default construct an empty stride range (0,0,0)
Definition: StrideRangeI.H:55
A tuple of integrals comprising start, size, stride. Caution: not properly tested for use with negati...
Definition: StrideRange.H:47
constexpr IntType rbegin_value() const noexcept
The max value of the end of start/size range.
Definition: StrideRangeI.H:110