zero.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
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 Class
28  Foam::zero
29 
30 Description
31  A class representing the concept of 0 (zero) that can be used to avoid
32  manipulating objects known to be \em zero at compile-time.
33  It is also used for tagged dispatch.
34 
35 SourceFiles
36  zero.C
37  zeroI.H
38 
39 SeeAlso
40  Foam::one
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef Foam_zero_H
45 #define Foam_zero_H
46 
47 #include "labelFwd.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class Istream;
56 class Ostream;
57 
58 /*---------------------------------------------------------------------------*\
59  Class zero Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class zero
63 {
64 public:
65 
66  //- The value type
67  typedef zero value_type;
68 
69  //- A static instance, when modifiable reference is required by an API
70  static zero dummy;
71 
72  //- Default construct
73  constexpr zero() noexcept {}
74 
75  //- Construct from Istream consumes no content.
76  explicit constexpr zero(Istream&) noexcept {}
77 
78 
79  //- Return false (0) for bool
80  constexpr operator bool() const noexcept { return false; }
81 
82  //- Return 0 for label
83  constexpr operator label() const noexcept { return 0; }
84 
85  //- Return 0 for float
86  constexpr operator float() const noexcept { return 0; }
87 
88  //- Return 0 for double
89  constexpr operator double() const noexcept { return 0; }
90 
91  //- Component-wise or element-wise access returns zero
92  zero operator[](const label) const noexcept { return zero{}; }
93 
94  // FUTURE?: Swallow assignment (as per std::ignore)
95  // template<class T>
96  // constexpr const zero& operator=(const T&) const { return *this; }
97 
98  //- Unary functor returns zero
99  template<class T>
100  constexpr zero operator()(const T&) const noexcept
101  {
102  return zero{};
103  }
104 };
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 //- Global zero (0)
110 static constexpr const zero Zero;
111 
112 // IOstream Operators
113 
114 //- Read from Istream consumes no content
115 inline constexpr Istream& operator>>(Istream& is, zero&) noexcept
116 {
117  return is;
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 } // End namespace Foam
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 // Global Operators, Functions
128 
129 #include "zeroI.H"
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 #endif
135 // ************************************************************************* //
constexpr zero operator()(const T &) const noexcept
Unary functor returns zero.
Definition: zero.H:115
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr zero() noexcept
Default construct.
Definition: zero.H:74
zero operator[](const label) const noexcept
Component-wise or element-wise access returns zero.
Definition: zero.H:105
Typedefs for label/uLabel without requiring label.H.
Istream & operator>>(Istream &, directionInfo &)
static zero dummy
A static instance, when modifiable reference is required by an API.
Definition: zero.H:69
const direction noexcept
Definition: Scalar.H:258
zero value_type
The value type.
Definition: zero.H:64
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127