Reference documentation for deal.II version 9.5.0
\(\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// Copyright (C) 2019 - 2023 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_base_mutable_bind_h
17#define dealii_base_mutable_bind_h
18
19#include <deal.II/base/config.h>
20
23
24#include <tuple>
25#include <utility>
26
28
29namespace Utilities
30{
81 template <typename ReturnType, class... FunctionArgs>
83 {
84 public:
89 using TupleType = std::tuple<typename std::remove_cv<
90 typename std::remove_reference<FunctionArgs>::type>::type...>;
91
96 template <class FunctionType>
97 MutableBind(FunctionType function, FunctionArgs &&...arguments);
98
103 template <class FunctionType>
105
110 template <class FunctionType>
111 MutableBind(FunctionType function);
112
117 ReturnType
118 operator()() const;
119
124 void
126
131 void
132 set_arguments(FunctionArgs &&...arguments);
133
147 void
148 parse_arguments(const std::string & value_string,
149 const Patterns::PatternBase &pattern =
151
152 private:
156 const std::function<ReturnType(FunctionArgs...)> function;
157
163 };
164
165
166
186 template <typename ReturnType, class... FunctionArgs>
187 MutableBind<ReturnType, FunctionArgs...>
188 mutable_bind(ReturnType (*function)(FunctionArgs...),
190
194 template <typename ReturnType, class... FunctionArgs>
195 MutableBind<ReturnType, FunctionArgs...>
196 mutable_bind(std::function<ReturnType(FunctionArgs...)>,
198
209 template <typename ReturnType, class... FunctionArgs>
210 MutableBind<ReturnType, FunctionArgs...>
211 mutable_bind(ReturnType (*function)(FunctionArgs...));
212
216 template <typename ReturnType, class... FunctionArgs>
217 MutableBind<ReturnType, FunctionArgs...>
218 mutable_bind(std::function<ReturnType(FunctionArgs...)>);
219
220
221
222#ifndef DOXYGEN
223 template <typename ReturnType, class... FunctionArgs>
224 template <class FunctionType>
226 FunctionType function,
227 FunctionArgs &&...arguments)
228 : function(function)
229 , arguments(std::make_tuple(std::move(arguments)...))
230 {}
231
232
233
234 template <typename ReturnType, class... FunctionArgs>
235 template <class FunctionType>
236 MutableBind<ReturnType, FunctionArgs...>::MutableBind(FunctionType function,
237 TupleType && arguments)
238 : function(function)
239 , arguments(std::move(arguments))
240 {}
241
242
243
244 template <typename ReturnType, class... FunctionArgs>
245 template <class FunctionType>
246 MutableBind<ReturnType, FunctionArgs...>::MutableBind(FunctionType function)
247 : function(function)
248 {}
249
250
251
252 template <typename ReturnType, class... FunctionArgs>
253 ReturnType
254 MutableBind<ReturnType, FunctionArgs...>::operator()() const
255 {
256 return std_cxx17::apply(function, arguments);
257 }
258
259
260
261 template <typename ReturnType, class... FunctionArgs>
262 void
263 MutableBind<ReturnType, FunctionArgs...>::set_arguments(
264 FunctionArgs &&...args)
265 {
266 arguments = std::make_tuple(std::move(args)...);
267 }
268
269
270
271 template <typename ReturnType, class... FunctionArgs>
272 void
273 MutableBind<ReturnType, FunctionArgs...>::set_arguments(TupleType &&args)
274 {
275 arguments = std::move(args);
276 }
277
278
279
280 template <typename ReturnType, class... FunctionArgs>
281 void
282 MutableBind<ReturnType, FunctionArgs...>::parse_arguments(
283 const std::string & value_string,
284 const Patterns::PatternBase &pattern)
285 {
286 arguments =
288 }
289
290
291
292 template <typename ReturnType, class... FunctionArgs>
293 MutableBind<ReturnType, FunctionArgs...>
294 mutable_bind(ReturnType (*function)(FunctionArgs...),
296 {
297 return MutableBind<ReturnType, FunctionArgs...>(function,
298 std::move(arguments)...);
299 }
300
301
302
303 template <typename ReturnType, class... FunctionArgs>
304 MutableBind<ReturnType, FunctionArgs...>
305 mutable_bind(ReturnType (*function)(FunctionArgs...))
306 {
307 return MutableBind<ReturnType, FunctionArgs...>(function);
308 }
309
310
311
312 template <typename ReturnType, class... FunctionArgs>
313 MutableBind<ReturnType, FunctionArgs...>
314 mutable_bind(std::function<ReturnType(FunctionArgs...)> function,
316 {
317 return MutableBind<ReturnType, FunctionArgs...>(function,
318 std::move(arguments)...);
319 }
320
321
322
323 template <typename ReturnType, class... FunctionArgs>
324 MutableBind<ReturnType, FunctionArgs...>
325 mutable_bind(std::function<ReturnType(FunctionArgs...)> function)
326 {
327 return MutableBind<ReturnType, FunctionArgs...>(function);
328 }
329#endif
330} // namespace Utilities
331
333
334#endif
std::tuple< typename std::remove_cv< typename std::remove_reference< FunctionArgs >::type >::type... > TupleType
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())
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
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:96
STL namespace.
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete