Reference documentation for deal.II version GIT relicensing-428-g838b4164b1 2024-04-19 07:00:02+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: 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// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_base_mutable_bind_h
16#define dealii_base_mutable_bind_h
17
18#include <deal.II/base/config.h>
19
21
22#include <tuple>
23#include <utility>
24
26
27namespace Utilities
28{
79 template <typename ReturnType, class... FunctionArgs>
81 {
82 public:
87 using TupleType =
88 std::tuple<std::remove_cv_t<std::remove_reference_t<FunctionArgs>>...>;
89
94 template <typename FunctionType>
95 MutableBind(FunctionType function, FunctionArgs &&...arguments);
96
101 template <typename FunctionType>
103
108 template <typename FunctionType>
109 MutableBind(FunctionType function);
110
115 ReturnType
116 operator()() const;
117
122 void
124
129 void
130 set_arguments(FunctionArgs &&...arguments);
131
145 void
146 parse_arguments(const std::string &value_string,
147 const Patterns::PatternBase &pattern =
149
150 private:
154 const std::function<ReturnType(FunctionArgs...)> function;
155
161 };
162
163
164
184 template <typename ReturnType, class... FunctionArgs>
185 MutableBind<ReturnType, FunctionArgs...>
186 mutable_bind(ReturnType (*function)(FunctionArgs...),
188
192 template <typename ReturnType, class... FunctionArgs>
193 MutableBind<ReturnType, FunctionArgs...>
194 mutable_bind(std::function<ReturnType(FunctionArgs...)>,
196
207 template <typename ReturnType, class... FunctionArgs>
208 MutableBind<ReturnType, FunctionArgs...>
209 mutable_bind(ReturnType (*function)(FunctionArgs...));
210
214 template <typename ReturnType, class... FunctionArgs>
215 MutableBind<ReturnType, FunctionArgs...>
216 mutable_bind(std::function<ReturnType(FunctionArgs...)>);
217
218
219
220#ifndef DOXYGEN
221 template <typename ReturnType, class... FunctionArgs>
222 template <typename FunctionType>
224 FunctionType function,
225 FunctionArgs &&...arguments)
226 : function(function)
227 , arguments(std::make_tuple(std::move(arguments)...))
228 {}
229
230
231
232 template <typename ReturnType, class... FunctionArgs>
233 template <typename FunctionType>
234 MutableBind<ReturnType, FunctionArgs...>::MutableBind(FunctionType function,
235 TupleType &&arguments)
236 : function(function)
237 , arguments(std::move(arguments))
238 {}
239
240
241
242 template <typename ReturnType, class... FunctionArgs>
243 template <typename FunctionType>
244 MutableBind<ReturnType, FunctionArgs...>::MutableBind(FunctionType function)
246 {}
247
248
249
250 template <typename ReturnType, class... FunctionArgs>
251 ReturnType
252 MutableBind<ReturnType, FunctionArgs...>::operator()() const
253 {
254 return std::apply(function, arguments);
255 }
256
257
258
259 template <typename ReturnType, class... FunctionArgs>
260 void
261 MutableBind<ReturnType, FunctionArgs...>::set_arguments(
262 FunctionArgs &&...args)
263 {
264 arguments = std::make_tuple(std::move(args)...);
265 }
266
267
268
269 template <typename ReturnType, class... FunctionArgs>
270 void
271 MutableBind<ReturnType, FunctionArgs...>::set_arguments(TupleType &&args)
272 {
273 arguments = std::move(args);
274 }
275
276
277
278 template <typename ReturnType, class... FunctionArgs>
279 void
280 MutableBind<ReturnType, FunctionArgs...>::parse_arguments(
281 const std::string &value_string,
282 const Patterns::PatternBase &pattern)
283 {
284 arguments =
286 }
287
288
289
290 template <typename ReturnType, class... FunctionArgs>
291 MutableBind<ReturnType, FunctionArgs...>
292 mutable_bind(ReturnType (*function)(FunctionArgs...),
294 {
295 return MutableBind<ReturnType, FunctionArgs...>(function,
296 std::move(arguments)...);
297 }
298
299
300
301 template <typename ReturnType, class... FunctionArgs>
302 MutableBind<ReturnType, FunctionArgs...>
303 mutable_bind(ReturnType (*function)(FunctionArgs...))
304 {
305 return MutableBind<ReturnType, FunctionArgs...>(function);
306 }
307
308
309
310 template <typename ReturnType, class... FunctionArgs>
311 MutableBind<ReturnType, FunctionArgs...>
312 mutable_bind(std::function<ReturnType(FunctionArgs...)> function,
314 {
315 return MutableBind<ReturnType, FunctionArgs...>(function,
316 std::move(arguments)...);
317 }
318
319
320
321 template <typename ReturnType, class... FunctionArgs>
322 MutableBind<ReturnType, FunctionArgs...>
323 mutable_bind(std::function<ReturnType(FunctionArgs...)> function)
324 {
325 return MutableBind<ReturnType, FunctionArgs...>(function);
326 }
327#endif
328} // namespace Utilities
329
331
332#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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
MutableBind< ReturnType, FunctionArgs... > mutable_bind(ReturnType(*function)(FunctionArgs...), std_cxx20::type_identity_t< FunctionArgs > &&...arguments)
const InputIterator OutputIterator const Function & function
Definition parallel.h:168
typename type_identity< T >::type type_identity_t
Definition type_traits.h:95
STL namespace.
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete