RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
constant.hh
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the C++-library RFFGen. */
4 /* Copyright 2015 Lars Lubkoll */
5 /* */
6 /* RFFGen is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* RFFGen is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with RFFGen. If not, see <http://www.gnu.org/licenses/>. */
18 /* */
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 
21 #ifndef RFFGEN_CONSTANT_HH
22 #define RFFGEN_CONSTANT_HH
23 
24 #include "Util/base.hh"
25 #include "Util/chainer.hh"
26 
27 namespace RFFGen
28 {
32  template <class> struct ArithmeticConceptCheck;
40  template <class Type, class = ArithmeticConceptCheck<Type> >
41  struct Constant : Base , Chainer< Constant<Type , ArithmeticConceptCheck<Type> > >
42  {
43  Constant() = default;
44 
46  Constant(Type const& t_) : t(t_)
47  {}
48 
50  const Type& d0() const noexcept
51  {
52  return t;
53  }
54 
55  private:
56  Type t;
57  };
58 
64  template <class Arg>
65  auto constRef(const Arg& x)
66  {
67  return Constant<const Arg&>(x);
68  }
69 
74  template <class Arg>
75  auto constant(const Arg& x)
76  {
77  return Constant<Arg>(x);
78  }
79 }
80 
81 #endif // RFFGEN_CONSTANT_HH
82 
const Type & d0() const noexcept
Function value.
Definition: constant.hh:50
auto constant(const Arg &x)
Wrap a constant.
Definition: constant.hh:75
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
auto constRef(const Arg &x)
Generate a constant function that stores its argument as constant reference.
Definition: constant.hh:65
Wrap a constant.
Definition: constant.hh:41
Constant(Type const &t_)
Construct constant from copy.
Definition: constant.hh:46