UniformList.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) 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 Class
27  Foam::UniformList
28 
29 Description
30  A single value that is represented as a list with an
31  operator[] to access the value.
32  This can be useful for templated operations expecting a list accessor.
33 
34 Note
35  The list currently has no sizing associated with it.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef UniformList_H
40 #define UniformList_H
41 
42 #include "labelFwd.H"
43 #include <utility>
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class UniformList Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class T>
55 class UniformList
56 {
57  // Private Data
58 
59  //- The value to be returned.
60  T value_;
61 
62 public:
63 
64  // Constructors
65 
66  //- Construct from given value
67  explicit UniformList(const T& val) noexcept
68  :
69  value_(val)
70  {}
71 
72  //- Move construct from given value
73  explicit UniformList(T&& val) noexcept
74  :
75  value_(std::move(val))
76  {}
77 
78 
79  // Member Functions
80 
81  //- Return the value
82  const T& value() const noexcept
83  {
84  return value_;
85  }
86 
87  //- Non-const access to the value
88  T& value() noexcept
89  {
90  return value_;
91  }
92 
93 
94  // Member Operators
95 
96  //- Implicit cast to the value
97  operator const T&() const noexcept
98  {
99  return value_;
100  }
101 
102  //- Return the value
103  const T& operator[](const label) const noexcept
104  {
105  return value_;
106  }
107 };
108 
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 } // End namespace Foam
113 
114 #endif
115 
116 // ************************************************************************* //
Foam::UniformList::UniformList
UniformList(T &&val) noexcept
Move construct from given value.
Definition: UniformList.H:72
Foam::UniformList::UniformList
UniformList(const T &val) noexcept
Construct from given value.
Definition: UniformList.H:66
Foam::UniformList::value
T & value() noexcept
Non-const access to the value.
Definition: UniformList.H:87
Foam::UniformList::operator[]
const T & operator[](const label) const noexcept
Return the value.
Definition: UniformList.H:102
Foam::UniformList
A single value that is represented as a list with an operator[] to access the value....
Definition: UniformList.H:54
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
labelFwd.H
Typedefs for label/uLabel without requiring label.H.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::UniformList::value
const T & value() const noexcept
Return the value.
Definition: UniformList.H:81