deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
mutable_bind.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2019 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_base_mutable_bind_h
14#define dealii_base_mutable_bind_h
15
16#include <deal.II/base/config.h>
17
19
20#include <tuple>
21#include <utility>
22
24
25namespace Utilities
26{
77 template <typename ReturnType, class... FunctionArgs>
79 {
80 public:
85 using TupleType =
86 std::tuple<std::remove_cv_t<std::remove_reference_t<FunctionArgs>>...>;
87
92 template <typename FunctionType>
93 MutableBind(FunctionType function, FunctionArgs &&...arguments);
94
99 template <typename FunctionType>
101
106 template <typename FunctionType>
107 MutableBind(FunctionType function);
108
113 ReturnType
114 operator()() const;
115
120 void
122
127 void
128 set_arguments(FunctionArgs &&...arguments);
129
143 void
144 parse_arguments(const std::string &value_string,
145 const Patterns::PatternBase &pattern =
147
148 private:
152 const std::function<ReturnType(FunctionArgs...)> function;
153
159 };
160
161
162
182 template <typename ReturnType, class... FunctionArgs>
183 MutableBind<ReturnType, FunctionArgs...>
184 mutable_bind(ReturnType (*function)(FunctionArgs...),
186
190 template <typename ReturnType, class... FunctionArgs>
191 MutableBind<ReturnType, FunctionArgs...>
192 mutable_bind(std::function<ReturnType(FunctionArgs...)>,
194
205 template <typename ReturnType, class... FunctionArgs>
206 MutableBind<ReturnType, FunctionArgs...>
207 mutable_bind(ReturnType (*function)(FunctionArgs...));
208
212 template <typename ReturnType, class... FunctionArgs>
213 MutableBind<ReturnType, FunctionArgs...>
214 mutable_bind(std::function<ReturnType(FunctionArgs...)>);
215
216
217
218#ifndef DOXYGEN
219 template <typename ReturnType, class... FunctionArgs>
220 template <typename FunctionType>
222 FunctionType function,
223 FunctionArgs &&...arguments)
224 : function(function)
225 , arguments(std::make_tuple(std::move(arguments)...))
226 {}
227
228
229
230 template <typename ReturnType, class... FunctionArgs>
231 template <typename FunctionType>
232 MutableBind<ReturnType, FunctionArgs...>::MutableBind(FunctionType function,
233 TupleType &&arguments)
234 : function(function)
235 , arguments(std::move(arguments))
236 {}
237
238
239
240 template <typename ReturnType, class... FunctionArgs>
241 template <typename FunctionType>
242 MutableBind<ReturnType, FunctionArgs...>::MutableBind(FunctionType function)
243 : function(function)
244 {}
245
246
247
248 template <typename ReturnType, class... FunctionArgs>
249 ReturnType
250 MutableBind<ReturnType, FunctionArgs...>::operator()() const
251 {
252 return std::apply(function, arguments);
253 }
254
255
256
257 template <typename ReturnType, class... FunctionArgs>
258 void
259 MutableBind<ReturnType, FunctionArgs...>::set_arguments(
260 FunctionArgs &&...args)
261 {
262 arguments = std::make_tuple(std::move(args)...);
263 }
264
265
266
267 template <typename ReturnType, class... FunctionArgs>
268 void
269 MutableBind<ReturnType, FunctionArgs...>::set_arguments(TupleType &&args)
270 {
271 arguments = std::move(args);
272 }
273
274
275
276 template <typename ReturnType, class... FunctionArgs>
277 void
278 MutableBind<ReturnType, FunctionArgs...>::parse_arguments(
279 const std::string &value_string,
280 const Patterns::PatternBase &pattern)
281 {
282 arguments =
284 }
285
286
287
288 template <typename ReturnType, class... FunctionArgs>
289 MutableBind<ReturnType, FunctionArgs...>
290 mutable_bind(ReturnType (*function)(FunctionArgs...),
292 {
293 return MutableBind<ReturnType, FunctionArgs...>(function,
294 std::move(arguments)...);
295 }
296
297
298
299 template <typename ReturnType, class... FunctionArgs>
300 MutableBind<ReturnType, FunctionArgs...>
301 mutable_bind(ReturnType (*function)(FunctionArgs...))
302 {
303 return MutableBind<ReturnType, FunctionArgs...>(function);
304 }
305
306
307
308 template <typename ReturnType, class... FunctionArgs>
309 MutableBind<ReturnType, FunctionArgs...>
310 mutable_bind(std::function<ReturnType(FunctionArgs...)> function,
312 {
313 return MutableBind<ReturnType, FunctionArgs...>(function,
314 std::move(arguments)...);
315 }
316
317
318
319 template <typename ReturnType, class... FunctionArgs>
320 MutableBind<ReturnType, FunctionArgs...>
321 mutable_bind(std::function<ReturnType(FunctionArgs...)> function)
322 {
323 return MutableBind<ReturnType, FunctionArgs...>(function);
324 }
325#endif
326} // namespace Utilities
327
329
330#endif
ReturnType operator()() const
MutableBind(FunctionType function)
void set_arguments(FunctionArgs &&...arguments)
MutableBind(FunctionType function, TupleType &&arguments)
const std::function< ReturnType(FunctionArgs...)> function
void set_arguments(TupleType &&arguments)
MutableBind(FunctionType function, FunctionArgs &&...arguments)
void parse_arguments(const std::string &value_string, const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< TupleType >::to_pattern())
std::tuple< std::remove_cv_t< std::remove_reference_t< FunctionArgs > >... > TupleType
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
MutableBind< ReturnType, FunctionArgs... > mutable_bind(ReturnType(*function)(FunctionArgs...), std_cxx20::type_identity_t< FunctionArgs > &&...arguments)
typename type_identity< T >::type type_identity_t
Definition type_traits.h:93
STL namespace.
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete