Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
invoke
Description

Calls a Deferred Callable Object with the arguments from a 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.

/functional/invocation/invoke.hpp>

Example
std::plus<int> add;
assert(invoke(add,make_vector(1,1)) == 2);
See also

PrevUpHomeNext