Reference documentation for deal.II version Git 78a8940608 2021-04-17 09:24:19 -0400
\(\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\}}\)
mutable_bind.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 - 2020 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 
21 #include <deal.II/base/patterns.h>
23 
24 #include <tuple>
25 #include <utility>
26 
28 
29 namespace 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>
104  MutableBind(FunctionType function, TupleType &&arguments);
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...),
189  typename identity<FunctionArgs>::type &&... arguments);
190 
194  template <typename ReturnType, class... FunctionArgs>
195  MutableBind<ReturnType, FunctionArgs...>
196  mutable_bind(std::function<ReturnType(FunctionArgs...)>,
197  typename identity<FunctionArgs>::type &&... arguments);
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>
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>
247  : function(function)
248  {}
249 
250 
251 
252  template <typename ReturnType, class... FunctionArgs>
253  ReturnType
255  {
256  return std_cxx17::apply(function, arguments);
257  }
258 
259 
260 
261  template <typename ReturnType, class... FunctionArgs>
262  void
264  FunctionArgs &&... args)
265  {
266  arguments = std::make_tuple(std::move(args)...);
267  }
268 
269 
270 
271  template <typename ReturnType, class... FunctionArgs>
272  void
274  {
275  arguments = std::move(args);
276  }
277 
278 
279 
280  template <typename ReturnType, class... FunctionArgs>
281  void
283  const std::string & value_string,
284  const Patterns::PatternBase &pattern)
285  {
286  arguments =
287  Patterns::Tools::Convert<TupleType>::to_value(value_string, pattern);
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
MutableBind(FunctionType function, FunctionArgs &&... arguments)
const std::function< ReturnType(FunctionArgs...)> function
Definition: mutable_bind.h:156
STL namespace.
void parse_arguments(const std::string &value_string, const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< TupleType >::to_pattern())
ReturnType operator()() const
void set_arguments(TupleType &&arguments)
MutableBind< ReturnType, FunctionArgs... > mutable_bind(ReturnType(*function)(FunctionArgs...), typename identity< FunctionArgs >::type &&... arguments)
auto apply(F &&fn, Tuple &&t) -> decltype(apply_impl(std::forward< F >(fn), std::forward< Tuple >(t), std::make_index_sequence< std::tuple_size< typename std::remove_reference< Tuple >::type >::value >()))
Definition: tuple.h:36
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:396
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete
std::tuple< typename std::remove_cv< typename std::remove_reference< FunctionArgs >::type >::type... > TupleType
Definition: mutable_bind.h:90
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:395