RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
identity.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_IDENTITY_HH
22 #define RFFGEN_IDENTITY_HH
23 
24 #include "Util/base.hh"
25 #include "Util/chainer.hh"
26 
27 namespace RFFGen
28 {
32  template <class> struct ArithmeticConceptCheck;
37  template <class Arg, class = ArithmeticConceptCheck<Arg> >
39  struct Identity : Base , Chainer< Identity<Arg,ArithmeticConceptCheck<Arg> > >
40  {
42  Identity() = default;
43 
48  Identity(const Arg& x) { update(x); }
49 
51  void update(const Arg& x)
52  {
53  x_ = x;
54  }
55 
57  const Arg& d0() const noexcept { return x_; }
58 
60  template <int>
61  const Arg& d1(const Arg& dx) const noexcept { return dx; }
62 
63  private:
64  Arg x_;
65  };
66 
68  template <class Arg>
69  auto identity(const Arg& x)
70  {
71  return Identity<Arg>(x);
72  }
73 }
74 
75 #endif // RFFGEN_IDENTITY_HH
Identity(const Arg &x)
Constructor.
Definition: identity.hh:48
Identity()=default
Default constructor.
const Arg & d1(const Arg &dx) const noexcept
First directional derivative.
Definition: identity.hh:61
auto identity(const Arg &x)
Construct Identity<Arg>(x).
Definition: identity.hh:69
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Identity mapping .
Definition: identity.hh:39
void update(const Arg &x)
Reset point of evaluation.
Definition: identity.hh:51
const Arg & d0() const noexcept
Function value.
Definition: identity.hh:57