stdFoam.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) 2017-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Namespace
27  stdFoam
28 
29 Description
30  Global macros and templates used by OpenFOAM and some standard
31  C++ headers.
32 
33  Some of the templates defined here correspond to useful
34  std templates that are part of future C++ standards, or that
35  are in a state of change. Defining them here provides some additional
36  control over which definitions are used within the OpenFOAM code-base.
37 
38 SeeAlso
39  - http://en.cppreference.com/w/cpp/iterator/begin
40  - http://en.cppreference.com/w/cpp/iterator/end
41  - http://en.cppreference.com/w/cpp/iterator/rbegin
42  - http://en.cppreference.com/w/cpp/iterator/rend
43 
44 \*---------------------------------------------------------------------------*/
45 
46 #ifndef stdFoam_H
47 #define stdFoam_H
48 
49 #include <initializer_list>
50 #include <utility>
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 // Compile-time warning for use of deprecated methods (compiler-dependent).
55 // Use within the class declaration.
56 
57 #if defined(__cplusplus) && (__cplusplus >= 201402L)
58 # define FOAM_DEPRECATED(since) [[deprecated("Since " #since)]]
59 # define FOAM_DEPRECATED_FOR(since, replacement) [[deprecated("Since " #since "; use " #replacement)]]
60 #elif defined(__GNUC__)
61 # define FOAM_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
62 # define FOAM_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
63 #else
64 # define FOAM_DEPRECATED(since)
65 # define FOAM_DEPRECATED_FOR(since, replacement)
66 #endif
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 //- Namespace for OpenFOAM
71 namespace Foam
72 {
73  //- Implementation details for various OpenFOAM classes
74  namespace Detail {}
75 
76  //- Additional OpenFOAM modules
77  namespace Module {}
78 }
79 
80 
81 namespace stdFoam
82 {
83 
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
85 
86 // Forward iteration
87 
88 //- Return iterator to the beginning of the container \a c.
89 // Definition as per std::begin C++17
90 template<class C>
91 constexpr auto begin(C& c) -> decltype(c.begin())
92 {
93  return c.begin();
94 }
95 
96 //- Return const_iterator to the beginning of the container \a c.
97 // Definition as per std::begin C++17
98 template<class C>
99 constexpr auto begin(const C& c) -> decltype(c.begin())
100 {
101  return c.begin();
102 }
103 
104 //- Return const_iterator to the beginning of the container \a c.
105 // Definition as per std::cbegin C++17
106 template<class C>
107 constexpr auto cbegin(const C& c) -> decltype(c.begin())
108 {
109  return c.begin();
110 }
111 
112 //- Return iterator to the end of the container \a c.
113 // Definition as per std::end C++17
114 template<class C>
115 constexpr auto end(C& c) -> decltype(c.end())
116 {
117  return c.end();
118 }
119 
120 //- Return const_iterator to the end of the container \a c.
121 // Definition as per std::end C++17
122 template<class C>
123 constexpr auto end(const C& c) -> decltype(c.end())
124 {
125  return c.end();
126 }
127 
128 //- Return const_iterator to the end of the container \a c.
129 // Definition as per std::cend C++17
130 template<class C>
131 constexpr auto cend(const C& c) -> decltype(c.end())
132 {
133  return c.end();
134 }
135 
136 
137 // Reverse iteration
138 
139 //- Return reverse_iterator to the reverse-begin of container \a c.
140 // Definition as per std::rbegin C++17
141 template<class C>
142 constexpr auto rbegin(C& c) -> decltype(c.rbegin())
143 {
144  return c.rbegin();
145 }
146 
147 //- Return const_reverse_iterator to the reverse-begin of container \a c.
148 // Definition as per std::rbegin C++17
149 template<class C>
150 constexpr auto rbegin(const C& c) -> decltype(c.rbegin())
151 {
152  return c.rbegin();
153 }
154 
155 //- Return const_reverse_iterator to the reverse-begin of container \a c.
156 // Definition as per std::crbegin C++17
157 template<class C>
158 constexpr auto crbegin(const C& c) -> decltype(c.rbegin())
159 {
160  return c.rbegin();
161 }
162 
163 //- Return reverse_iterator to reverse-end of container \a c.
164 // Definition as per std::rend C++17
165 template<class C>
166 constexpr auto rend(C& c) -> decltype(c.rend())
167 {
168  return c.rend();
169 }
170 
171 //- Return const_reverse_iterator to reverse-end of container \a c.
172 // Definition as per std::rend C++17
173 template<class C>
174 constexpr auto rend(const C& c) -> decltype(c.rend())
175 {
176  return c.rend();
177 }
178 
179 //- Return const_reverse_iterator to reverse-end of container \a c.
180 // Definition as per std::crend C++17
181 template<class C>
182 constexpr auto crend(const C& c) -> decltype(c.rend())
183 {
184  return c.rend();
185 }
186 
187 //- Return the lesser of the parameters.
188 // Definition as per std::min C++14
189 template<class T>
190 constexpr inline const T& min(const T& a, const T& b)
191 {
192  return (b < a) ? b : a;
193 }
194 
195 //- Return the greater of the parameters.
196 // Definition as per std::max C++14
197 template<class T>
198 constexpr inline const T& max(const T& a, const T& b)
199 {
200  return (a < b) ? b : a;
201 }
202 
203 } // End namespace stdFoam
204 
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 //- Iterate across all elements in the \a container object.
209 // \par Usage
210 // \code
211 // forAllIters(container, iter)
212 // {
213 // statements;
214 // }
215 // \endcode
216 // \sa forAllConstIters, forAllIter, forAllConstIters
217 #define forAllIters(container,iter) \
218  for \
219  ( \
220  auto iter = stdFoam::begin(container); \
221  iter != stdFoam::end(container); \
222  ++iter \
223  )
224 
225 
226 //- Iterate across all elements of the \a container object with const access.
227 // \par Usage
228 // \code
229 // forAllConstIters(container, iter)
230 // {
231 // statements;
232 // }
233 // \endcode
234 // \sa forAllIters, forAllIter, forAllConstIter
235 #define forAllConstIters(container,iter) \
236  for \
237  ( \
238  auto iter = stdFoam::cbegin(container); \
239  iter != stdFoam::cend(container); \
240  ++iter \
241  )
242 
243 
244 //- Reverse iterate across elements in the \a container object of type
245 // \a Container.
246 // \par Usage
247 // \code
248 // forAllReverseIters(container, iter)
249 // {
250 // statements;
251 // }
252 // \endcode
253 // \sa forAllConstReverseIters
254 #define forAllReverseIters(container,iter) \
255  for \
256  ( \
257  auto iter = stdFoam::rbegin(container); \
258  iter != stdFoam::rend(container); \
259  ++iter \
260  )
261 
262 
263 //- Reverse iterate across elements of \a container object with const access.
264 // \par Usage
265 // \code
266 // forAllReverseConstIters(container, iter)
267 // {
268 // statements;
269 // }
270 // \endcode
271 // \sa forAllReverseIters
272 #define forAllConstReverseIters(container,iter) \
273  for \
274  ( \
275  auto iter = stdFoam::crbegin(container); \
276  iter != stdFoam::crend(container); \
277  ++iter \
278  )
279 
280 
281 //- Loop across all elements in \a list
282 // \par Usage
283 // \code
284 // forAll(anyList, i)
285 // {
286 // statements;
287 // }
288 // \endcode
289 // \sa forAllReverse
290 #define forAll(list, i) \
291  for (Foam::label i=0; i<(list).size(); ++i)
292 
293 
294 //- Reverse loop across all elements in \a list
295 // \par Usage
296 // \code
297 // forAllReverse(anyList, i)
298 // {
299 // statements;
300 // }
301 // \endcode
302 // \sa forAll
303 #define forAllReverse(list, i) \
304  for (Foam::label i=(list).size()-1; i>=0; --i)
305 
306 
307 // Compatibility macros for pre C++11
308 
309 //- Iterate across all elements in the \a container object
310 // of type \a Container.
311 // \par Usage
312 // \code
313 // forAllIter(ContainerType, container, iter)
314 // {
315 // statements;
316 // }
317 // \endcode
318 // \sa forAllConstIter
319 #define forAllIter(Container,container,iter) \
320  for \
321  ( \
322  Container::iterator iter = (container).begin(); \
323  iter != (container).end(); \
324  ++iter \
325  )
326 
327 
328 //- Iterate across all elements in the \a container object
329 // of type \a Container with const access.
330 // \par Usage
331 // \code
332 // forAllConstIter(ContainerType, container, iter)
333 // {
334 // statements;
335 // }
336 // \endcode
337 // \sa forAllIter
338 #define forAllConstIter(Container,container,iter) \
339  for \
340  ( \
341  Container::const_iterator iter = (container).cbegin(); \
342  iter != (container).cend(); \
343  ++iter \
344  )
345 
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 #endif
350 
351 // ************************************************************************* //
forAllConstReverseIters
#define forAllConstReverseIters(container, iter)
Reverse iterate across elements of container object with const access.
Definition: stdFoam.H:272
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:319
stdFoam
Global macros and templates used by OpenFOAM and some standard C++ headers.
stdFoam::crend
constexpr auto crend(const C &c) -> decltype(c.rend())
Return const_reverse_iterator to reverse-end of container c.
Definition: stdFoam.H:182
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:91
stdFoam::begin
constexpr auto begin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
Definition: stdFoam.H:99
forAllConstIters
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:235
forAllConstIter
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:338
C
volScalarField & C
Definition: readThermalProperties.H:102
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
stdFoam::crbegin
constexpr auto crbegin(const C &c) -> decltype(c.rbegin())
Return const_reverse_iterator to the reverse-begin of container c.
Definition: stdFoam.H:158
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
stdFoam::end
constexpr auto end(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
Definition: stdFoam.H:123
forAllIters
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:217
stdFoam::max
constexpr const T & max(const T &a, const T &b)
Return the greater of the parameters.
Definition: stdFoam.H:198
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:115
stdFoam::rbegin
constexpr auto rbegin(C &c) -> decltype(c.rbegin())
Return reverse_iterator to the reverse-begin of container c.
Definition: stdFoam.H:142
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
T
const volScalarField & T
Definition: createFieldRefs.H:2
stdFoam::cend
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
Definition: stdFoam.H:131
stdFoam::min
constexpr const T & min(const T &a, const T &b)
Return the lesser of the parameters.
Definition: stdFoam.H:190
stdFoam::cbegin
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
Definition: stdFoam.H:107
forAllReverseIters
#define forAllReverseIters(container, iter)
Reverse iterate across elements in the container object of type.
Definition: stdFoam.H:254
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:303
stdFoam::rend
constexpr auto rend(C &c) -> decltype(c.rend())
Return reverse_iterator to reverse-end of container c.
Definition: stdFoam.H:166