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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Description
27 Includes some standard C++ headers, defines global macros and templates
28 used in multiple places by OpenFOAM.
29
30\*---------------------------------------------------------------------------*/
31
32#ifndef Foam_stdFoam_H
33#define Foam_stdFoam_H
34
35#include <initializer_list>
36#include <memory>
37#include <utility>
38
39// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40
41// Compile-time warning for use of deprecated methods (compiler-dependent).
42// Use within the class declaration.
43
44#if (__cplusplus >= 201402L)
45# define FOAM_DEPRECATED(since) [[deprecated("Since " #since)]]
46# define FOAM_DEPRECATED_FOR(since, replacement) [[deprecated("Since " #since "; use " #replacement)]]
47#elif defined(__GNUC__)
48# define FOAM_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
49# define FOAM_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
50#else
51# define FOAM_DEPRECATED(since)
52# define FOAM_DEPRECATED_FOR(since, replacement)
53#endif
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57//- Namespace for OpenFOAM
58namespace Foam
59{
60
61//- Implementation details for various OpenFOAM classes
62namespace Detail {}
63
64//- Additional OpenFOAM modules
65namespace Module {}
66
67// Standard items
68
69//- Allow use of std::unique_ptr directly as Foam::unique_ptr
70using std::unique_ptr;
71
72
73//- A functor that returns its argument unchanged (cf. C++20 std::identity)
74//- Should \em never be specialized.
76{
77 using is_transparent = void;
78
79 template<class T>
80 constexpr T&& operator()(T&& val) const noexcept
81 {
82 return std::forward<T>(val);
83 }
84};
85
86
87//- Swap non-array types as per std::swap, but in Foam namespace.
88// \sa http://www.cplusplus.com/reference/utility/swap/
89//
90// \note For complex structures, it is usual to provide a swap() member
91// function and specialize Swap()
92template<class T>
93void Swap(T& a, T& b)
94{
95 std::swap(a, b);
96}
97
98
99//- Swap array types as per std::swap example, but in Foam namespace.
100// \sa http://www.cplusplus.com/reference/utility/swap/
101template<class T, size_t N>
102void Swap(T (&a)[N], T (&b)[N])
103{
104 for (size_t i = 0; i < N; ++i)
105 {
106 Foam::Swap(a[i], b[i]);
107 }
108}
109
110} // End namespace Foam
111
112
113// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114
115//- Namespace for std templates that are are part of future C++ standards
116//- or that are in a state of change.
117//
118// SeeAlso
119// - http://en.cppreference.com/w/cpp/iterator/begin
120// - http://en.cppreference.com/w/cpp/iterator/end
121// - http://en.cppreference.com/w/cpp/iterator/rbegin
122// - http://en.cppreference.com/w/cpp/iterator/rend
123
124namespace stdFoam
125{
126
127// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128
129// Forward iteration
130
131//- Return iterator to the beginning of the container \a c.
132// Definition as per std::begin C++17
133template<class C>
134constexpr auto begin(C& c) -> decltype(c.begin())
135{
136 return c.begin();
137}
138
139//- Return const_iterator to the beginning of the container \a c.
140// Definition as per std::begin C++17
141template<class C>
142constexpr auto begin(const C& c) -> decltype(c.begin())
143{
144 return c.begin();
145}
146
147//- Return const_iterator to the beginning of the container \a c.
148// Definition as per std::cbegin C++17
149template<class C>
150constexpr auto cbegin(const C& c) -> decltype(c.begin())
151{
152 return c.begin();
153}
154
155//- Return iterator to the end of the container \a c.
156// Definition as per std::end C++17
157template<class C>
158constexpr auto end(C& c) -> decltype(c.end())
159{
160 return c.end();
161}
162
163//- Return const_iterator to the end of the container \a c.
164// Definition as per std::end C++17
165template<class C>
166constexpr auto end(const C& c) -> decltype(c.end())
167{
168 return c.end();
169}
170
171//- Return const_iterator to the end of the container \a c.
172// Definition as per std::cend C++17
173template<class C>
174constexpr auto cend(const C& c) -> decltype(c.end())
175{
176 return c.end();
177}
178
179
180// Reverse iteration
181
182//- Return reverse_iterator to the reverse-begin of container \a c.
183// Definition as per std::rbegin C++17
184template<class C>
185constexpr auto rbegin(C& c) -> decltype(c.rbegin())
186{
187 return c.rbegin();
188}
189
190//- Return const_reverse_iterator to the reverse-begin of container \a c.
191// Definition as per std::rbegin C++17
192template<class C>
193constexpr auto rbegin(const C& c) -> decltype(c.rbegin())
194{
195 return c.rbegin();
196}
197
198//- Return const_reverse_iterator to the reverse-begin of container \a c.
199// Definition as per std::crbegin C++17
200template<class C>
201constexpr auto crbegin(const C& c) -> decltype(c.rbegin())
202{
203 return c.rbegin();
204}
205
206//- Return reverse_iterator to reverse-end of container \a c.
207// Definition as per std::rend C++17
208template<class C>
209constexpr auto rend(C& c) -> decltype(c.rend())
210{
211 return c.rend();
212}
213
214//- Return const_reverse_iterator to reverse-end of container \a c.
215// Definition as per std::rend C++17
216template<class C>
217constexpr auto rend(const C& c) -> decltype(c.rend())
218{
219 return c.rend();
220}
221
222//- Return const_reverse_iterator to reverse-end of container \a c.
223// Definition as per std::crend C++17
224template<class C>
225constexpr auto crend(const C& c) -> decltype(c.rend())
226{
227 return c.rend();
228}
229
230//- Return the lesser of the parameters.
231// Definition as per std::min C++14
232template<class T>
233constexpr inline const T& min(const T& a, const T& b)
234{
235 return (b < a) ? b : a;
236}
237
238//- Return the greater of the parameters.
239// Definition as per std::max C++14
240template<class T>
241constexpr inline const T& max(const T& a, const T& b)
242{
243 return (a < b) ? b : a;
244}
245
246} // End namespace stdFoam
247
248
249// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250
251//- Iterate across all elements in the \a container object.
252// \par Usage
253// \code
254// forAllIters(container, iter)
255// {
256// statements;
257// }
258// \endcode
259// \sa forAllConstIters, forAllIter, forAllConstIters
260#define forAllIters(container,iter) \
261 for \
262 ( \
263 auto iter = stdFoam::begin(container); \
264 iter != stdFoam::end(container); \
265 ++iter \
266 )
267
268
269//- Iterate across all elements of the \a container object with const access.
270// \par Usage
271// \code
272// forAllConstIters(container, iter)
273// {
274// statements;
275// }
276// \endcode
277// \sa forAllIters, forAllIter, forAllConstIter
278#define forAllConstIters(container,iter) \
279 for \
280 ( \
281 auto iter = stdFoam::cbegin(container); \
282 iter != stdFoam::cend(container); \
283 ++iter \
284 )
285
286
287//- Reverse iterate across elements in the \a container object of type
288// \a Container.
289// \par Usage
290// \code
291// forAllReverseIters(container, iter)
292// {
293// statements;
294// }
295// \endcode
296// \sa forAllConstReverseIters
297#define forAllReverseIters(container,iter) \
298 for \
299 ( \
300 auto iter = stdFoam::rbegin(container); \
301 iter != stdFoam::rend(container); \
302 ++iter \
303 )
304
305
306//- Reverse iterate across elements of \a container object with const access.
307// \par Usage
308// \code
309// forAllReverseConstIters(container, iter)
310// {
311// statements;
312// }
313// \endcode
314// \sa forAllReverseIters
315#define forAllConstReverseIters(container,iter) \
316 for \
317 ( \
318 auto iter = stdFoam::crbegin(container); \
319 iter != stdFoam::crend(container); \
320 ++iter \
321 )
322
323
324//- Loop across all elements in \a list
325// \par Usage
326// \code
327// forAll(anyList, i)
328// {
329// statements;
330// }
331// \endcode
332// \sa forAllReverse
333#define forAll(list, i) \
334 for (Foam::label i=0; i<(list).size(); ++i)
335
336
337//- Reverse loop across all elements in \a list
338// \par Usage
339// \code
340// forAllReverse(anyList, i)
341// {
342// statements;
343// }
344// \endcode
345// \sa forAll
346#define forAllReverse(list, i) \
347 for (Foam::label i=(list).size()-1; i>=0; --i)
348
349
350// Compatibility macros for pre C++11
351
352//- Iterate across all elements in the \a container object
353// of type \a Container.
354// \par Usage
355// \code
356// forAllIter(ContainerType, container, iter)
357// {
358// statements;
359// }
360// \endcode
361// \sa forAllConstIter
362#define forAllIter(Container,container,iter) \
363 for \
364 ( \
365 Container::iterator iter = (container).begin(); \
366 iter != (container).end(); \
367 ++iter \
368 )
369
370
371//- Iterate across all elements in the \a container object
372// of type \a Container with const access.
373// \par Usage
374// \code
375// forAllConstIter(ContainerType, container, iter)
376// {
377// statements;
378// }
379// \endcode
380// \sa forAllIter
381#define forAllConstIter(Container,container,iter) \
382 for \
383 ( \
384 Container::const_iterator iter = (container).cbegin(); \
385 iter != (container).cend(); \
386 ++iter \
387 )
388
389
390// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391
392#endif
393
394// ************************************************************************* //
static const Foam::dimensionedScalar C("", Foam::dimTemperature, 234.5)
const volScalarField & T
Namespace for OpenFOAM.
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Definition: DynamicList.H:408
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
Definition: stdFoam.H:174
constexpr auto crbegin(const C &c) -> decltype(c.rbegin())
Return const_reverse_iterator to the reverse-begin of container c.
Definition: stdFoam.H:201
constexpr const T & min(const T &a, const T &b)
Return the lesser of the parameters.
Definition: stdFoam.H:233
constexpr const T & max(const T &a, const T &b)
Return the greater of the parameters.
Definition: stdFoam.H:241
constexpr auto crend(const C &c) -> decltype(c.rend())
Return const_reverse_iterator to reverse-end of container c.
Definition: stdFoam.H:225
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:158
constexpr auto rbegin(C &c) -> decltype(c.rbegin())
Return reverse_iterator to the reverse-begin of container c.
Definition: stdFoam.H:185
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
Definition: stdFoam.H:150
constexpr auto rend(C &c) -> decltype(c.rend())
Return reverse_iterator to reverse-end of container c.
Definition: stdFoam.H:209
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:134
volScalarField & b
Definition: createFields.H:27
#define forAllConstReverseIters(container, iter)
Reverse iterate across elements of container object with const access.
Definition: stdFoam.H:315
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:362
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:346
#define forAllReverseIters(container, iter)
Reverse iterate across elements in the container object of type.
Definition: stdFoam.H:297
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:260
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:381
void is_transparent
Definition: stdFoam.H:77
constexpr T && operator()(T &&val) const noexcept
Definition: stdFoam.H:80
const Vector< label > N(dict.get< Vector< label > >("N"))