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-2020 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 <memory>
51 #include <utility>
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 // Compile-time warning for use of deprecated methods (compiler-dependent).
56 // Use within the class declaration.
57 
58 #if (__cplusplus >= 201402L)
59 # define FOAM_DEPRECATED(since) [[deprecated("Since " #since)]]
60 # define FOAM_DEPRECATED_FOR(since, replacement) [[deprecated("Since " #since "; use " #replacement)]]
61 #elif defined(__GNUC__)
62 # define FOAM_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
63 # define FOAM_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
64 #else
65 # define FOAM_DEPRECATED(since)
66 # define FOAM_DEPRECATED_FOR(since, replacement)
67 #endif
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 //- Namespace for OpenFOAM
72 namespace Foam
73 {
74  //- Implementation details for various OpenFOAM classes
75  namespace Detail {}
76 
77  //- Additional OpenFOAM modules
78  namespace Module {}
79 
80  // Standard items
81 
82  //- Allow use of std::unique_ptr directly as Foam::unique_ptr
83  using std::unique_ptr;
84 }
85 
86 
87 namespace stdFoam
88 {
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 // Forward iteration
93 
94 //- Return iterator to the beginning of the container \a c.
95 // Definition as per std::begin C++17
96 template<class C>
97 constexpr auto begin(C& c) -> decltype(c.begin())
98 {
99  return c.begin();
100 }
101 
102 //- Return const_iterator to the beginning of the container \a c.
103 // Definition as per std::begin C++17
104 template<class C>
105 constexpr auto begin(const C& c) -> decltype(c.begin())
106 {
107  return c.begin();
108 }
109 
110 //- Return const_iterator to the beginning of the container \a c.
111 // Definition as per std::cbegin C++17
112 template<class C>
113 constexpr auto cbegin(const C& c) -> decltype(c.begin())
114 {
115  return c.begin();
116 }
117 
118 //- Return iterator to the end of the container \a c.
119 // Definition as per std::end C++17
120 template<class C>
121 constexpr auto end(C& c) -> decltype(c.end())
122 {
123  return c.end();
124 }
125 
126 //- Return const_iterator to the end of the container \a c.
127 // Definition as per std::end C++17
128 template<class C>
129 constexpr auto end(const C& c) -> decltype(c.end())
130 {
131  return c.end();
132 }
133 
134 //- Return const_iterator to the end of the container \a c.
135 // Definition as per std::cend C++17
136 template<class C>
137 constexpr auto cend(const C& c) -> decltype(c.end())
138 {
139  return c.end();
140 }
141 
142 
143 // Reverse iteration
144 
145 //- Return reverse_iterator to the reverse-begin of container \a c.
146 // Definition as per std::rbegin C++17
147 template<class C>
148 constexpr auto rbegin(C& c) -> decltype(c.rbegin())
149 {
150  return c.rbegin();
151 }
152 
153 //- Return const_reverse_iterator to the reverse-begin of container \a c.
154 // Definition as per std::rbegin C++17
155 template<class C>
156 constexpr auto rbegin(const C& c) -> decltype(c.rbegin())
157 {
158  return c.rbegin();
159 }
160 
161 //- Return const_reverse_iterator to the reverse-begin of container \a c.
162 // Definition as per std::crbegin C++17
163 template<class C>
164 constexpr auto crbegin(const C& c) -> decltype(c.rbegin())
165 {
166  return c.rbegin();
167 }
168 
169 //- Return reverse_iterator to reverse-end of container \a c.
170 // Definition as per std::rend C++17
171 template<class C>
172 constexpr auto rend(C& c) -> decltype(c.rend())
173 {
174  return c.rend();
175 }
176 
177 //- Return const_reverse_iterator to reverse-end of container \a c.
178 // Definition as per std::rend C++17
179 template<class C>
180 constexpr auto rend(const C& c) -> decltype(c.rend())
181 {
182  return c.rend();
183 }
184 
185 //- Return const_reverse_iterator to reverse-end of container \a c.
186 // Definition as per std::crend C++17
187 template<class C>
188 constexpr auto crend(const C& c) -> decltype(c.rend())
189 {
190  return c.rend();
191 }
192 
193 //- Return the lesser of the parameters.
194 // Definition as per std::min C++14
195 template<class T>
196 constexpr inline const T& min(const T& a, const T& b)
197 {
198  return (b < a) ? b : a;
199 }
200 
201 //- Return the greater of the parameters.
202 // Definition as per std::max C++14
203 template<class T>
204 constexpr inline const T& max(const T& a, const T& b)
205 {
206  return (a < b) ? b : a;
207 }
208 
209 } // End namespace stdFoam
210 
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 //- Iterate across all elements in the \a container object.
215 // \par Usage
216 // \code
217 // forAllIters(container, iter)
218 // {
219 // statements;
220 // }
221 // \endcode
222 // \sa forAllConstIters, forAllIter, forAllConstIters
223 #define forAllIters(container,iter) \
224  for \
225  ( \
226  auto iter = stdFoam::begin(container); \
227  iter != stdFoam::end(container); \
228  ++iter \
229  )
230 
231 
232 //- Iterate across all elements of the \a container object with const access.
233 // \par Usage
234 // \code
235 // forAllConstIters(container, iter)
236 // {
237 // statements;
238 // }
239 // \endcode
240 // \sa forAllIters, forAllIter, forAllConstIter
241 #define forAllConstIters(container,iter) \
242  for \
243  ( \
244  auto iter = stdFoam::cbegin(container); \
245  iter != stdFoam::cend(container); \
246  ++iter \
247  )
248 
249 
250 //- Reverse iterate across elements in the \a container object of type
251 // \a Container.
252 // \par Usage
253 // \code
254 // forAllReverseIters(container, iter)
255 // {
256 // statements;
257 // }
258 // \endcode
259 // \sa forAllConstReverseIters
260 #define forAllReverseIters(container,iter) \
261  for \
262  ( \
263  auto iter = stdFoam::rbegin(container); \
264  iter != stdFoam::rend(container); \
265  ++iter \
266  )
267 
268 
269 //- Reverse iterate across elements of \a container object with const access.
270 // \par Usage
271 // \code
272 // forAllReverseConstIters(container, iter)
273 // {
274 // statements;
275 // }
276 // \endcode
277 // \sa forAllReverseIters
278 #define forAllConstReverseIters(container,iter) \
279  for \
280  ( \
281  auto iter = stdFoam::crbegin(container); \
282  iter != stdFoam::crend(container); \
283  ++iter \
284  )
285 
286 
287 //- Loop across all elements in \a list
288 // \par Usage
289 // \code
290 // forAll(anyList, i)
291 // {
292 // statements;
293 // }
294 // \endcode
295 // \sa forAllReverse
296 #define forAll(list, i) \
297  for (Foam::label i=0; i<(list).size(); ++i)
298 
299 
300 //- Reverse loop across all elements in \a list
301 // \par Usage
302 // \code
303 // forAllReverse(anyList, i)
304 // {
305 // statements;
306 // }
307 // \endcode
308 // \sa forAll
309 #define forAllReverse(list, i) \
310  for (Foam::label i=(list).size()-1; i>=0; --i)
311 
312 
313 // Compatibility macros for pre C++11
314 
315 //- Iterate across all elements in the \a container object
316 // of type \a Container.
317 // \par Usage
318 // \code
319 // forAllIter(ContainerType, container, iter)
320 // {
321 // statements;
322 // }
323 // \endcode
324 // \sa forAllConstIter
325 #define forAllIter(Container,container,iter) \
326  for \
327  ( \
328  Container::iterator iter = (container).begin(); \
329  iter != (container).end(); \
330  ++iter \
331  )
332 
333 
334 //- Iterate across all elements in the \a container object
335 // of type \a Container with const access.
336 // \par Usage
337 // \code
338 // forAllConstIter(ContainerType, container, iter)
339 // {
340 // statements;
341 // }
342 // \endcode
343 // \sa forAllIter
344 #define forAllConstIter(Container,container,iter) \
345  for \
346  ( \
347  Container::const_iterator iter = (container).cbegin(); \
348  iter != (container).cend(); \
349  ++iter \
350  )
351 
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 #endif
356 
357 // ************************************************************************* //
forAllConstReverseIters
#define forAllConstReverseIters(container, iter)
Reverse iterate across elements of container object with const access.
Definition: stdFoam.H:278
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:325
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:188
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:97
stdFoam::begin
constexpr auto begin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
Definition: stdFoam.H:105
forAllConstIters
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:241
forAllConstIter
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:344
C
volScalarField & C
Definition: readThermalProperties.H:102
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
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:164
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:129
forAllIters
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:223
stdFoam::max
constexpr const T & max(const T &a, const T &b)
Return the greater of the parameters.
Definition: stdFoam.H:204
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
stdFoam::rbegin
constexpr auto rbegin(C &c) -> decltype(c.rbegin())
Return reverse_iterator to the reverse-begin of container c.
Definition: stdFoam.H:148
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:137
stdFoam::min
constexpr const T & min(const T &a, const T &b)
Return the lesser of the parameters.
Definition: stdFoam.H:196
stdFoam::cbegin
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
Definition: stdFoam.H:113
forAllReverseIters
#define forAllReverseIters(container, iter)
Reverse iterate across elements in the container object of type.
Definition: stdFoam.H:260
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:309
stdFoam::rend
constexpr auto rend(C &c) -> decltype(c.rend())
Return reverse_iterator to reverse-end of container c.
Definition: stdFoam.H:172