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
81  {
82  return false;
83  }
84 
85  //- Return 0 for label
86  constexpr operator label() const noexcept
87  {
88  return 0;
89  }
90 
91  //- Return 0 for float
92  constexpr operator float() const noexcept
93  {
94  return 0;
95  }
96 
97  //- Return 0 for double
98  constexpr operator double() const noexcept
99  {
100  return 0;
101  }
102 
103  //- Component-wise or element-wise access returns zero
104  zero operator[](const label) const noexcept
105  {
106  return zero{};
107  }
108 
109  // FUTURE?: Swallow assignment (as per std::ignore)
110  // template<class T>
111  // constexpr const zero& operator=(const T&) const { return *this; }
112 };
113 
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 //- Global zero (0)
118 static constexpr const zero Zero;
119 
120 // IOstream Operators
121 
122 //- Read from Istream consumes no content
123 inline constexpr Istream& operator>>(Istream& is, zero&) noexcept
124 {
125  return is;
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130 
131 } // End namespace Foam
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 // Global Operators, Functions
136 
137 #include "zeroI.H"
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 #endif
142 
143 // ************************************************************************* //
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:117
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
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:133