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