piranha  0.10
Public Types | Public Member Functions | List of all members
piranha::math::lambdified< T, U > Class Template Reference

Functor interface for piranha::math::evaluate(). More...

#include <piranha/lambdify.hpp>

Public Types

using eval_type = decltype(math::evaluate(std::declval< const T & >(), std::declval< const symbol_fmap< U > & >()))
 Evaluation type. More...
 
using extra_map_type = std::unordered_map< std::string, std::function< U(const std::vector< U > &)> >
 The map type for the custom evaluation of symbols. More...
 

Public Member Functions

 lambdified (const T &x, const std::vector< std::string > &names, extra_map_type extra_map={})
 Constructor. More...
 
 lambdified (T &&x, const std::vector< std::string > &names, extra_map_type extra_map={})
 Constructor (move overload). More...
 
 lambdified (const lambdified &other)
 Copy constructor. More...
 
 lambdified (lambdified &&other)
 Move constructor. More...
 
eval_type operator() (const std::vector< U > &values)
 Evaluation. More...
 
const T & get_evaluable () const
 Get evaluation object. More...
 
const std::vector< std::string > & get_names () const
 Get evaluation names. More...
 
std::vector< std::string > get_extra_names () const
 Get names of the symbols in the extra map. More...
 

Detailed Description

template<typename T, typename U>
class piranha::math::lambdified< T, U >

Functor interface for piranha::math::evaluate().

This class exposes a function-like interface for the evaluation of instances of type T with objects of type U. The class acts as a small wrapper for piranha::math::evaluate() which replaces the interface based on std::unordered_map with an interface based on vectors and positional arguments.

The convenience function piranha::math::lambdify() can be used to easily construct objects of this class.

Type requirements

Exception safety guarantee

Unless otherwise specified, this class provides the strong exception safety guarantee for all operations.

Move semantics

After a move operation, an object of this class is destructible.

Definition at line 88 of file lambdify.hpp.

Member Typedef Documentation

◆ eval_type

template<typename T , typename U >
using piranha::math::lambdified< T, U >::eval_type = decltype(math::evaluate(std::declval<const T &>(), std::declval<const symbol_fmap<U> &>()))

Evaluation type.

This is the type resulting from evaluating objects of type T with objects of type U via piranha::math::evaluate().

Definition at line 150 of file lambdify.hpp.

◆ extra_map_type

template<typename T , typename U >
using piranha::math::lambdified< T, U >::extra_map_type = std::unordered_map<std::string, std::function<U(const std::vector<U> &)> >

The map type for the custom evaluation of symbols.

See the constructor documentation for an explanation of how this type is used.

Definition at line 155 of file lambdify.hpp.

Constructor & Destructor Documentation

◆ lambdified() [1/4]

template<typename T , typename U >
piranha::math::lambdified< T, U >::lambdified ( const T &  x,
const std::vector< std::string > &  names,
extra_map_type  extra_map = {} 
)
inlineexplicit

Constructor.

This constructor will create an internal copy of x, the object that will be evaluated by successive calls to operator()(). The vector of string names establishes the correspondence between symbols and the values with which the symbols will be replaced when operator()() is called. That is, the values in the vector passed to operator()() are associated to the symbols in names at the corresponding positions.

The optional argument extra_map can be used to specify how to evaluate specific symbols. That is, extra_map associates symbol names to functions of signature

U (const std::vector<U> &)

When operator()() is called with a vector of values v, for each symbol s in extra_map the associated function is called with v as an argument, and the return value is used as evaluation value for s in the subsequent call to math::evaluate(). extra_map must not contain symbol names appearing in names.

Parameters
xthe object that will be evaluated by operator()().
namesthe list of symbols to which the values passed to operator()() will be mapped.
extra_mapthe custom symbol evaluation map.
Exceptions
std::invalid_argumentif names contains duplicates or if extra_map contains symbol names already present in names.
unspecifiedany exception thrown by:
  • memory errors in standard containers,
  • the public interface of std::unordered_map,
  • the copy constructor of T,
  • the construction of objects of type U.

Definition at line 187 of file lambdify.hpp.

◆ lambdified() [2/4]

template<typename T , typename U >
piranha::math::lambdified< T, U >::lambdified ( T &&  x,
const std::vector< std::string > &  names,
extra_map_type  extra_map = {} 
)
inlineexplicit

Constructor (move overload).

This constructor is equivalent to the other constructor, the only difference being that x is used to move-construct (instead of copy-construct) the internal instance of T.

Parameters
xthe object that will be evaluated by operator()().
namesthe list of symbols to which the values passed to operator()() will be mapped.
extra_mapthe custom symbol evaluation map.
Exceptions
std::invalid_argumentif names contains duplicates or if extra_map contains symbol names already present in names.
unspecifiedany exception thrown by:
  • memory errors in standard containers,
  • the public interface of std::unordered_map,
  • the move constructor of T,
  • the construction of objects of type U.

Definition at line 209 of file lambdify.hpp.

◆ lambdified() [3/4]

template<typename T , typename U >
piranha::math::lambdified< T, U >::lambdified ( const lambdified< T, U > &  other)
inline

Copy constructor.

Parameters
othercopy argument.
Exceptions
unspecifiedany exception thrown by the copy constructor of the internal members.

Definition at line 220 of file lambdify.hpp.

◆ lambdified() [4/4]

template<typename T , typename U >
piranha::math::lambdified< T, U >::lambdified ( lambdified< T, U > &&  other)
inline

Move constructor.

Parameters
othermove argument.
Exceptions
unspecifiedany exception thrown by the move constructor of the internal members.

Definition at line 231 of file lambdify.hpp.

Member Function Documentation

◆ get_evaluable()

template<typename T , typename U >
const T& piranha::math::lambdified< T, U >::get_evaluable ( ) const
inline

Get evaluation object.

Returns
a const reference to the internal copy of the object of type T created upon construction.

Definition at line 304 of file lambdify.hpp.

◆ get_extra_names()

template<typename T , typename U >
std::vector<std::string> piranha::math::lambdified< T, U >::get_extra_names ( ) const
inline

Get names of the symbols in the extra map.

Returns
a vector containing the names of the symbols in the extra_map used during construction.
Exceptions
unspecifiedany exception thrown by memory errors in standard containers.

Definition at line 322 of file lambdify.hpp.

◆ get_names()

template<typename T , typename U >
const std::vector<std::string>& piranha::math::lambdified< T, U >::get_names ( ) const
inline

Get evaluation names.

Returns
a const reference to the vector of symbol names used as second construction argument.

Definition at line 312 of file lambdify.hpp.

◆ operator()()

template<typename T , typename U >
eval_type piranha::math::lambdified< T, U >::operator() ( const std::vector< U > &  values)
inline

Evaluation.

The call operator will first associate the elements of values to the vector of names used to construct this, and it will then call piranha::math::evaluate() on the stored internal instance of the object of type T used during construction.

If a non-empty extra_map parameter was used during construction, the symbols in it are evaluated according to the mapped functions before being passed down in the evaluation dictionary to piranha::math::evaluate().

Note that this function needs to modify the internal state of the object, and thus it is not const and it is not thread-safe.

Parameters
valuesthe values that will be used for evaluation.
Returns
the output of piranha::math::evaluate() called on the instance of type T stored internally.
Exceptions
std::invalid_argumentif the size of values is not equal to the size of the vector of names used during construction.
unspecifiedany exception raised by:
  • the copy-assignment operator of U,
  • math::evaluate(),
  • the call operator of the mapped functions in the extra_map parameter used during construction.

Definition at line 269 of file lambdify.hpp.


The documentation for this class was generated from the following file: