Reference documentation for deal.II version 9.2.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\}}\)
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>
24 
25 #include <tuple>
26 
28 
29 namespace Utilities
30 {
83  template <typename ReturnType, class... FunctionArgs>
85  {
86  public:
91  using TupleType = std::tuple<typename std::remove_cv<
92  typename std::remove_reference<FunctionArgs>::type>::type...>;
93 
98  template <class FunctionType>
99  MutableBind(FunctionType function, FunctionArgs &&... arguments);
100 
105  template <class FunctionType>
106  MutableBind(FunctionType function, TupleType &&arguments);
107 
112  template <class FunctionType>
113  MutableBind(FunctionType function);
114 
119  ReturnType
120  operator()() const;
121 
126  void
128 
133  void
134  set_arguments(FunctionArgs &&... arguments);
135 
149  void
150  parse_arguments(const std::string & value_string,
151  const std::unique_ptr<Patterns::PatternBase> &pattern =
153 
154  private:
158  const std::function<ReturnType(FunctionArgs...)> function;
159 
165  };
166 
167 
168 
190  template <typename ReturnType, class... FunctionArgs>
191  MutableBind<ReturnType, FunctionArgs...>
192  mutable_bind(ReturnType (*function)(FunctionArgs...),
193  typename identity<FunctionArgs>::type &&... arguments);
194 
198  template <typename ReturnType, class... FunctionArgs>
199  MutableBind<ReturnType, FunctionArgs...>
200  mutable_bind(std::function<ReturnType(FunctionArgs...)>,
201  typename identity<FunctionArgs>::type &&... arguments);
202 
213  template <typename ReturnType, class... FunctionArgs>
214  MutableBind<ReturnType, FunctionArgs...>
215  mutable_bind(ReturnType (*function)(FunctionArgs...));
216 
220  template <typename ReturnType, class... FunctionArgs>
221  MutableBind<ReturnType, FunctionArgs...>
222  mutable_bind(std::function<ReturnType(FunctionArgs...)>);
223 
224 
225 
226 #ifndef DOXYGEN
227  template <typename ReturnType, class... FunctionArgs>
228  template <class FunctionType>
230  FunctionType function,
231  FunctionArgs &&... arguments)
232  : function(function)
233  , arguments(std::make_tuple(std::move(arguments)...))
234  {}
235 
236 
237 
238  template <typename ReturnType, class... FunctionArgs>
239  template <class FunctionType>
241  TupleType && arguments)
242  : function(function)
243  , arguments(std::move(arguments))
244  {}
245 
246 
247 
248  template <typename ReturnType, class... FunctionArgs>
249  template <class FunctionType>
251  : function(function)
252  {}
253 
254 
255 
256  template <typename ReturnType, class... FunctionArgs>
257  ReturnType
259  {
260  return std_cxx17::apply(function, arguments);
261  }
262 
263 
264 
265  template <typename ReturnType, class... FunctionArgs>
266  void
268  FunctionArgs &&... args)
269  {
270  arguments = std::make_tuple(std::move(args)...);
271  }
272 
273 
274 
275  template <typename ReturnType, class... FunctionArgs>
276  void
278  {
279  arguments = std::move(args);
280  }
281 
282 
283 
284  template <typename ReturnType, class... FunctionArgs>
285  void
287  const std::string & value_string,
288  const std::unique_ptr<Patterns::PatternBase> &pattern)
289  {
290  arguments =
291  Patterns::Tools::Convert<TupleType>::to_value(value_string, pattern);
292  }
293 
294 
295 
296  template <typename ReturnType, class... FunctionArgs>
297  MutableBind<ReturnType, FunctionArgs...>
298  mutable_bind(ReturnType (*function)(FunctionArgs...),
299  typename identity<FunctionArgs>::type &&... arguments)
300  {
301  return MutableBind<ReturnType, FunctionArgs...>(function,
302  std::move(arguments)...);
303  }
304 
305 
306 
307  template <typename ReturnType, class... FunctionArgs>
308  MutableBind<ReturnType, FunctionArgs...>
309  mutable_bind(ReturnType (*function)(FunctionArgs...))
310  {
311  return MutableBind<ReturnType, FunctionArgs...>(function);
312  }
313 
314 
315 
316  template <typename ReturnType, class... FunctionArgs>
317  MutableBind<ReturnType, FunctionArgs...>
318  mutable_bind(std::function<ReturnType(FunctionArgs...)> function,
319  typename identity<FunctionArgs>::type &&... arguments)
320  {
321  return MutableBind<ReturnType, FunctionArgs...>(function,
322  std::move(arguments)...);
323  }
324 
325 
326 
327  template <typename ReturnType, class... FunctionArgs>
328  MutableBind<ReturnType, FunctionArgs...>
329  mutable_bind(std::function<ReturnType(FunctionArgs...)> function)
330  {
331  return MutableBind<ReturnType, FunctionArgs...>(function);
332  }
333 #endif
334 } // namespace Utilities
335 
337 
338 #endif
identity::type
T type
Definition: template_constraints.h:270
Utilities::MutableBind::parse_arguments
void parse_arguments(const std::string &value_string, const std::unique_ptr< Patterns::PatternBase > &pattern=Patterns::Tools::Convert< TupleType >::to_pattern())
Utilities::MutableBind::MutableBind
MutableBind(FunctionType function, FunctionArgs &&... arguments)
Utilities::MutableBind::TupleType
std::tuple< typename std::remove_cv< typename std::remove_reference< FunctionArgs >::type >::type... > TupleType
Definition: mutable_bind.h:92
utility.h
Patterns::Tools::Convert
Definition: patterns.h:1305
tuple.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Utilities::MutableBind::operator()
ReturnType operator()() const
Utilities::MutableBind::arguments
TupleType arguments
Definition: mutable_bind.h:164
std_cxx17::apply
auto apply(F &&fn, Tuple &&t) -> decltype(apply_impl(std::forward< F >(fn), std::forward< Tuple >(t), std_cxx14::make_index_sequence< std::tuple_size< typename std::remove_reference< Tuple >::type >::value >()))
Definition: tuple.h:40
Patterns::Tools::Convert::to_value
static T to_value(const std::string &s, const std::unique_ptr< Patterns::PatternBase > &p=Convert< T >::to_pattern())=delete
config.h
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
patterns.h
Utilities::MutableBind::set_arguments
void set_arguments(TupleType &&arguments)
Utilities::MutableBind
Definition: mutable_bind.h:84
Utilities
Definition: cuda.h:31
Utilities::mutable_bind
MutableBind< ReturnType, FunctionArgs... > mutable_bind(ReturnType(*function)(FunctionArgs...), typename identity< FunctionArgs >::type &&... arguments)