Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Functions

invoke
invoke_procedure
invoke_function_object
Description

Calls a Deferred Callable Object with the arguments from a Sequence.

The corresponding metafunction, result_of::invoke does not define a type member for target functions of non-class type whose arity is not satisfied by the size of the sequence.

The first template parameter can be specialized explicitly to avoid copying and/or to control the const qualification of a function object.

If the target function is a pointer to a class members, the corresponding object can be specified as a reference, pointer, or smart pointer. In case of the latter, a freestanding get_pointer function must be defined (Boost provides this function for std::auto_ptr and boost::shared_ptr).

Synopsis
template<
    typename Function, 
    class Sequence
    >
typename result_of::invoke<Function, Sequence>::type
invoke(Function f, Sequence & s);

template<
    typename Function, 
    class Sequence
    >
typename result_of::invoke<Function, Sequence const>::type 
invoke(Function f, Sequence const & s);
Parameters
Parameter Requirement Description
f A Deferred Callable Object The function to call.
s A Forward Sequence The arguments.
Expression Semantics
invoke(f,s);

Return type: Return type of f when invoked with the elements in s as its arguments.

Semantics: Invokes f with the elements in s as arguments and returns the result of the call expression.

Header
#include <boost/fusion/functional/invocation/invoke.hpp>
Example
std::plus<int> add;
assert(invoke(add,make_vector(1,1)) == 2);
See also
Description

Calls a Callable Object with the arguments from a Sequence. The result of the call is ignored.

The corresponding metafunction, __result_of_invoke_procedure, does not define a type member for target functions of non-class type whose arity is not satisfied by the size of the sequence.

The first template parameter can be specialized explicitly to avoid copying and/or to control the const qualification of a function object.

For pointers to class members corresponding object can be specified as a reference, pointer, or smart pointer. In case of the latter, a freestanding get_pointer function must be defined (Boost provides this function for std::auto_ptr and boost::shared_ptr).

The target function must not be a pointer to a member object (dereferencing such a pointer without returning anything does not make sense, so it isn't implemented).

Synopsis
template<
    typename Function, 
    class Sequence
    >
typename result_of::invoke_procedure<Function, Sequence>::type
invoke_procedure(Function f, Sequence & s);

template<
    typename Function, 
    class Sequence
    >
typename result_of::invoke_procedure<Function, Sequence const>::type
invoke_procedure(Function f, Sequence const & s);
Parameters
Parameter Requirement Description
f Model of Callable Object The function to call.
s Model of Forward Sequence The arguments.
Expression Semantics
invoke_procedure(f,s);

Return type: void

Semantics: Invokes f with the elements in s as arguments.

Header
#include <boost/fusion/functional/invocation/invoke_procedure.hpp>
Example
vector<int,int> v(1,2);
using namespace boost::lambda;
invoke_procedure(_1 += _2, v);
assert(front(v) == 3);
See also
Description

Calls a Polymorphic Function Object with the arguments from a Sequence.

The corresponding metafunction, result_of::invoke_function_object, does not define a type member, if the nested result class template of the target function object is empty.

The first template parameter can be specialized explicitly to avoid copying and/or to control the const qualification of a function object.

Synopsis
template<
    typename Function, 
    class Sequence
    >
typename result_of::invoke_function_object<Function, Sequence>::type
invoke_function_object(Function f, Sequence & s);

template<
    typename Function, 
    class Sequence
    >
typename result_of::invoke_function_object<Function, Sequence const>::type
invoke_function_object(Function f, Sequence const & s);
Parameters
Parameter Requirement Description
f Model of Polymorphic Function Object The function object to call.
s Model of Forward Sequence The arguments.
Expression Semantics
invoke_procedure(f,s);

Return type: Return type of f when invoked with the elements in s as its arguments.

Semantics: Invokes f with the elements in s as arguments and returns the result of the call expression.

Header
#include <boost/fusion/functional/invocation/invoke_function_object.hpp>
Example
struct sub
{
    template<typename T, typename _>
    struct result
    {
        typedef T type;
    };

    template<typename T>
    T operator()(T lhs, T rhs) const
    {
        return lhs - rhs;
    }
};

void try_it()
{
    sub f;
    assert(f(2,1) == invoke_function_object(f,make_vector(2,1)));
}
See also
Copyright © 2001-2005 Joel de Guzman, Dan Marsden

PrevUpHomeNext