Dune Core Modules (2.9.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// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_FUNCTION_HH_SILENCE_DEPRECATION
6#warning This file is deprecated after Dune 2.7! Use C++ function objects and std::function stuff instead!
7#else // !DUNE_FUNCTION_HH_SILENCE_DEPRECATION
8#undef DUNE_FUNCTION_HH_SILENCE_DEPRECATION
9#endif // !DUNE_FUNCTION_HH_SILENCE_DEPRECATION
10
11#ifndef DUNE_FUNCTION_HH
12#define DUNE_FUNCTION_HH
13
14#include <utility>
15
17#include "typetraits.hh"
18
19namespace Dune {
20
36 template <class Domain, class Range>
37 class
38 [[deprecated("Dune::Function is deprecated after Dune 2.7. Use C++ "
39 "function objects instead!")]]
41 {
42 typedef typename std::remove_cv<typename std::remove_reference< Domain >::type >::type RawDomainType;
43 typedef typename std::remove_cv<typename std::remove_reference< Range >::type >::type RawRangeType;
44
45 public:
46
48 typedef RawRangeType RangeType;
49
51 typedef RawDomainType DomainType;
52
54 struct Traits
55 {
56 typedef RawDomainType DomainType;
57 typedef RawRangeType RangeType;
58 };
59
66 void evaluate(const typename Traits::DomainType& x, typename Traits::RangeType& y) const;
67 }; // end of Function class
68
69
70
82 template <class DomainType, class RangeType>
83 class
84 [[deprecated("Dune::VirtualFunction is deprecated after Dune 2.7. Use C++ "
85 "function objects and std::function instead!")]]
87 {
88 public:
90
91 virtual ~VirtualFunction() {}
98 virtual void evaluate(const typename Traits::DomainType& x, typename Traits::RangeType& y) const = 0;
99 }; // end of VirtualFunction class
101
102 namespace Impl {
103
105 template<typename Domain, typename Range, typename F>
106 class LambdaVirtualFunction final
107 : public VirtualFunction<Domain, Range>
108 {
109 public:
110 LambdaVirtualFunction(F&& f)
111 : f_(std::move(f))
112 {}
113
114 LambdaVirtualFunction(const F& f)
115 : f_(f)
116 {}
117
118 void evaluate(const Domain& x, Range& y) const override
119 {
120 y = f_(x);
121 }
122
123 private:
124 const F f_;
125 };
127
128 } /* namespace Impl */
129
149 template<typename Domain, typename Range, typename F>
150 [[deprecated("Dune::LambdaVirtualFunction is deprecated after Dune 2.7. "
151 "Use std::function instead!")]]
152 Impl::LambdaVirtualFunction< Domain, Range, std::decay_t<F> >
154 {
155 return {std::forward<F>(f)};
156 }
157
160} // end namespace
161
162#endif
Base class template for function classes.
Definition: function.hh:41
RawDomainType DomainType
Raw type of output variable with removed reference and constness.
Definition: function.hh:51
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:48
Virtual base class template for function classes.
Definition: function.hh:87
virtual void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const =0
Function evaluation.
Definition of the DUNE_NO_DEPRECATED_* macros.
Impl::LambdaVirtualFunction< Domain, Range, std::decay_t< F > > makeVirtualFunction(F &&f)
make VirtualFunction out of a function object
Definition: function.hh:153
#define DUNE_NO_DEPRECATED_END
Ignore deprecation warnings (end)
Definition: deprecated.hh:38
#define DUNE_NO_DEPRECATED_BEGIN
Ignore deprecation warnings (start)
Definition: deprecated.hh:32
Dune namespace.
Definition: alignedallocator.hh:13
Traits class containing raw types.
Definition: function.hh:55
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)