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\}}\)
Public Types | Public Member Functions | Private Attributes | List of all members
Utilities::MutableBind< ReturnType, FunctionArgs > Class Template Reference

#include <deal.II/base/mutable_bind.h>

Public Types

using TupleType = std::tuple< typename std::remove_cv< typename std::remove_reference< FunctionArgs >::type >::type... >
 

Public Member Functions

template<class FunctionType >
 MutableBind (FunctionType function, FunctionArgs &&... arguments)
 
template<class FunctionType >
 MutableBind (FunctionType function, TupleType &&arguments)
 
template<class FunctionType >
 MutableBind (FunctionType function)
 
ReturnType operator() () const
 
void set_arguments (TupleType &&arguments)
 
void set_arguments (FunctionArgs &&... arguments)
 
void parse_arguments (const std::string &value_string, const std::unique_ptr< Patterns::PatternBase > &pattern=Patterns::Tools::Convert< TupleType >::to_pattern())
 

Private Attributes

const std::function< ReturnType(FunctionArgs...)> function
 
TupleType arguments
 

Detailed Description

template<typename ReturnType, class... FunctionArgs>
class Utilities::MutableBind< ReturnType, FunctionArgs >

A mutable version of std::bind, that binds all arguments of a function pointer to a stored tuple, and allows you to update the tuple between calls.

An example usage of this class is through the helper function mutable_bind() that creates a MutableBind object on the fly, based on its arguments:

void my_function(const int &a, const double &b);
auto bound = mutable_bind(my_function, 1, 2.0);
bound(); // will execute my_function(1, 2.0);
bound.set_arguments(2, 3.0);
bound(); // will execute my_function(2, 3.0);
bound.parse_arguments("3: 4.0");
bound(); // will execute my_function(3, 4.0);

The arguments are copied to the tuple, with their reference and const attributes removed. Only copy constructible objects are allowed as function arguments. If you need to keep some references around, you may wrap your function into a lambda function:

void
example_function(const Point<2> &p,
const double &d,
const unsigned int i = 3) {
...
};
const Point<2> p(1, 2);
[&p](const double &d,
const unsigned int i)
{
example_function(p, d, i);
},
{}};
exp.parse_arguments("3.0 : 4");
exp(); // calls example_function(p, 3.0, 4);
Authors
Luca Heltai, Matthias Maier, 2019.

Definition at line 84 of file mutable_bind.h.

Member Typedef Documentation

◆ TupleType

template<typename ReturnType , class... FunctionArgs>
using Utilities::MutableBind< ReturnType, FunctionArgs >::TupleType = std::tuple<typename std::remove_cv< typename std::remove_reference<FunctionArgs>::type>::type...>

An alias to the stored std::tuple type. Only copy constructible objects are allowed as tuple members.

Definition at line 92 of file mutable_bind.h.

Constructor & Destructor Documentation

◆ MutableBind() [1/3]

template<typename ReturnType , class... FunctionArgs>
template<class FunctionType >
Utilities::MutableBind< ReturnType, FunctionArgs >::MutableBind ( FunctionType  function,
FunctionArgs &&...  arguments 
)

Construct a MutableBind object specifying the function, and each arguments separately.

◆ MutableBind() [2/3]

template<typename ReturnType , class... FunctionArgs>
template<class FunctionType >
Utilities::MutableBind< ReturnType, FunctionArgs >::MutableBind ( FunctionType  function,
TupleType &&  arguments 
)

Construct a MutableBind object specifying the function, and the arguments as a tuple.

◆ MutableBind() [3/3]

template<typename ReturnType , class... FunctionArgs>
template<class FunctionType >
Utilities::MutableBind< ReturnType, FunctionArgs >::MutableBind ( FunctionType  function)

Construct a MutableBind object specifying only the function. By default, the arguments are left to their default constructor values.

Member Function Documentation

◆ operator()()

template<typename ReturnType , class... FunctionArgs>
ReturnType Utilities::MutableBind< ReturnType, FunctionArgs >::operator() ( ) const

Call the original function, passing as arguments the elements of the tuple of bound arguments.

◆ set_arguments() [1/2]

template<typename ReturnType , class... FunctionArgs>
void Utilities::MutableBind< ReturnType, FunctionArgs >::set_arguments ( TupleType &&  arguments)

Set the arguments to use in function, for next time operator()() is called, using move semantic.

◆ set_arguments() [2/2]

template<typename ReturnType , class... FunctionArgs>
void Utilities::MutableBind< ReturnType, FunctionArgs >::set_arguments ( FunctionArgs &&...  arguments)

Set the arguments to use in function, for next time operator()() is called, using move semantic.

◆ parse_arguments()

template<typename ReturnType , class... FunctionArgs>
void Utilities::MutableBind< ReturnType, FunctionArgs >::parse_arguments ( const std::string &  value_string,
const std::unique_ptr< Patterns::PatternBase > &  pattern = Patterns::Tools::ConvertTupleType >::to_pattern() 
)

Parse the arguments to use in function from a string, for next time operator()() is called.

The conversion is performed using a user supplied Patterns::PatternBase object. By default, Patterns::Tools::Convert<TupleType>::to_pattern() is used to determine how to convert from value_string to a TupleType object.

Parameters
value_stringThe string to convert from
patternA unique pointer to the pattern to use when performing the conversion

Member Data Documentation

◆ function

template<typename ReturnType , class... FunctionArgs>
const std::function<ReturnType(FunctionArgs...)> Utilities::MutableBind< ReturnType, FunctionArgs >::function
private

An std::function that stores the original function.

Definition at line 158 of file mutable_bind.h.

◆ arguments

template<typename ReturnType , class... FunctionArgs>
TupleType Utilities::MutableBind< ReturnType, FunctionArgs >::arguments
private

Currently stored arguments. These are forwarded to the function object above, when calling operator()().

Definition at line 164 of file mutable_bind.h.


The documentation for this class was generated from the following file:
Physics::Elasticity::Kinematics::d
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
std::exp
::VectorizedArray< Number, width > exp(const ::VectorizedArray< Number, width > &)
Definition: vectorization.h:5368
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
Point< 2 >
Utilities::MutableBind
Definition: mutable_bind.h:84
Utilities::mutable_bind
MutableBind< ReturnType, FunctionArgs... > mutable_bind(ReturnType(*function)(FunctionArgs...), typename identity< FunctionArgs >::type &&... arguments)