Dune Core Modules (2.6.0)

function.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_FUNCTION_HH
4 #define DUNE_FUNCTION_HH
5 
6 #include <utility>
7 
8 #include "typetraits.hh"
9 
10 namespace Dune {
11 
27  template <class Domain, class Range>
28  class Function
29  {
30  typedef typename std::remove_cv<typename std::remove_reference< Domain >::type >::type RawDomainType;
31  typedef typename std::remove_cv<typename std::remove_reference< Range >::type >::type RawRangeType;
32 
33  public:
34 
36  typedef RawRangeType RangeType;
37 
39  typedef RawDomainType DomainType;
40 
42  struct Traits
43  {
44  typedef RawDomainType DomainType;
45  typedef RawRangeType RangeType;
46  };
47 
54  void evaluate(const typename Traits::DomainType& x, typename Traits::RangeType& y) const;
55  }; // end of Function class
56 
57 
58 
69  template <class DomainType, class RangeType>
71  public Function<const DomainType&, RangeType&>
72  {
73  public:
75 
76  virtual ~VirtualFunction() {}
83  virtual void evaluate(const typename Traits::DomainType& x, typename Traits::RangeType& y) const = 0;
84  }; // end of VirtualFunction class
85 
86  namespace Impl {
87 
88  template<typename Domain, typename Range, typename F>
89  class LambdaVirtualFunction final
90  : public VirtualFunction<Domain, Range>
91  {
92  public:
93  LambdaVirtualFunction(F&& f)
94  : f_(std::move(f))
95  {}
96 
97  LambdaVirtualFunction(const F& f)
98  : f_(f)
99  {}
100 
101  void evaluate(const Domain& x, Range& y) const override
102  {
103  y = f_(x);
104  }
105 
106  private:
107  const F f_;
108  };
109 
110  } /* namespace Impl */
111 
131  template<typename Domain, typename Range, typename F>
132  Impl::LambdaVirtualFunction< Domain, Range, std::decay_t<F> >
134  {
135  return {std::forward<F>(f)};
136  }
137 
140 } // end namespace
141 
142 #endif
Base class template for function classes.
Definition: function.hh:29
RawDomainType DomainType
Raw type of output variable with removed reference and constness.
Definition: function.hh:39
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Function evaluation.
RawRangeType RangeType
Raw type of input variable with removed reference and constness.
Definition: function.hh:36
Virtual base class template for function classes.
Definition: function.hh:72
virtual void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const =0
Function evaluation.
Impl::LambdaVirtualFunction< Domain, Range, std::decay_t< F > > makeVirtualFunction(F &&f)
make VirtualFunction out of a function object
Definition: function.hh:133
Dune namespace.
Definition: alignedallocator.hh:10
Traits class containing raw types.
Definition: function.hh:43
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 24, 22:30, 2024)