Definitions
A function object f is
compatible if for the given set of argument
types Arg1,
Arg2, ...,
ArgN and a
return type ResultType, the
appropriate following function is well-formed:
// if ResultType is not void
ResultType foo(Arg1 arg1, Arg2 arg2, ..., ArgN argN)
{
return f(arg1, arg2, ..., argN);
}
// if ResultType is void
ResultType foo(Arg1 arg1, Arg2 arg2, ..., ArgN argN)
{
f(arg1, arg2, ..., argN);
}
A special provision is made for pointers to member
functions. Though they are not function objects, Boost.Function
will adapt them internally to function objects. This requires
that a pointer to member function of the form R
(X::*mf)(Arg1, Arg2, ..., ArgN)
cv-quals
be adapted to a
function object with the following function call operator
overloads:
template<typename P>
R operator()(cv-quals P& x, Arg1 arg1, Arg2 arg2, ..., ArgN argN) const
{
return (*x).*mf(arg1, arg2, ..., argN);
}
A function object f
of
type F
is
stateless if it is a function pointer or if
boost::is_stateless<T>
is true. The construction of or copy to a Boost.Function object
from a stateless function object will not cause exceptions to be
thrown and will not allocate any storage.
std::runtime_error
An exception type thrown when an instance of a function
object is empty when invoked.
Constructs a bad_function_call
exception object.
The common base class for all Boost.Function
objects. Objects of type function_base may not be created
directly.
true
if this
has a target, and false
otherwise.
Will not throw.
std::allocator<void>
function_base
A set of generalized function pointers that can be used for callbacks or wrapping function objects.
Class template functionN is
actually a family of related classes function0, function1, etc., up to some
implementation-defined maximum. In this context, N
refers to the number of parameters.
R
Allocator
T1If N == 1
T1
If N == 2
T2
If N == 2
T1
T2
TN
this->empty()
Will not throw.
const functionN&
Contains a copy of the f
's target, if it has one, or is empty if f.empty()
.
Will not throw unless copying the target of f
throws.
F
F is a function object Callable from this
.
*this
targets a copy of f
if f
is nonempty, or this->empty()
if f
is empty.
Will not throw when f
is a stateless function object.
If !this->empty()
, destroys the target of this.
const functionN&
*this
targets a copy of f
's target, if it has one, or is empty if f.empty()
.
Will not throw when the target of f
is a stateless function object or a reference to the function object.
const functionN&
Interchanges the targets of *this
and f
.
Will not throw.
this->empty()
Will not throw.
bool
true
if this
has a target, and false
otherwise.
Will not throw.
A safe_bool
that evaluates false
in a boolean context when this->empty()
, and true
otherwise.
Will not throw.
this->empty()
Will not throw.
arg1_type
arg2_type
...
argN_type
f(a1, a2, ..., aN)
, where f
is the target of *this
.
if R
is void
, nothing is returned; otherwise, the return value of the call to f
is returned.
bad_function_call
if !this->empty()
. Otherwise, may through any exception thrown by the target function f
.
functionN<T1, T2, ..., TN, Allocator>&
functionN<T1, T2, ..., TN, Allocator>&
f1.swap(f2)
Will not throw.
const functionN<T1, T2, ..., TN, Allocator1>&
const functionN<U1, U2, ..., UN, Allocator2>&
This function must be left undefined.
The safe_bool
conversion opens a loophole whereby two function instances can be compared via ==
. This undefined void operator ==
closes the loophole and ensures a compile-time or link-time error.
const functionN<T1, T2, ..., TN, Allocator1>&
const functionN<U1, U2, ..., UN, Allocator2>&
This function must be left undefined.
The safe_bool
conversion opens a loophole whereby two function instances can be compared via !=
. This undefined void operator !=
closes the loophole and ensures a compile-time or link-time error.
std::allocator<void>
functionN<R, T1, T2, ..., TN, Allocator>
A generalized function pointer that can be used for
callbacks or wrapping function objects.
Class template function is a thin
wrapper around the numbered class templates function0, function1, etc. It accepts a
function type with N arguments and will will derive from
functionN instantiated with the arguments
it receives.
The semantics of all operations in class template
function are equivalent to that of the
underlying functionN object, although
additional member functions are required to allow proper copy
construction and copy assignment of function objects.
R
Allocator
T1If N == 1
T1
If N == 2
T2
If N == 2
T1
T2
TN
this->empty()
Will not throw.
const functionN&
Contains a copy of the f
's target, if it has one, or is empty if f.empty()
.
Will not throw unless copying the target of f
throws.
const function&
Contains a copy of the f
's target, if it has one, or is empty if f.empty()
.
Will not throw unless copying the target of f
throws.
F
F is a function object Callable from this
.
*this
targets a copy of f
if f
is nonempty, or this->empty()
if f
is empty.
Will not throw when f
is a stateless function object.
If !this->empty()
, destroys the target of this
.
const functionN&
*this
targets a copy of f
's target, if it has one, or is empty if f.empty()
Will not throw when the target of f
is a stateless function object or a reference to the function object.
const function&
*this
targets a copy of f
's target, if it has one, or is empty if f.empty()
Will not throw when the target of f
is a stateless function object or a reference to the function object.
const function&
Interchanges the targets of *this
and f
.
Will not throw.
this->empty()
Will not throw.
true
if this
has a target, and false
otherwise.
Will not throw.
A safe_bool
that evaluates false
in a boolean context when this->empty()
, and true
otherwise.
Will not throw.
this->empty()
Will not throw.
arg1_type
arg2_type
...
argN_type
f(a1, a2, ..., aN)
, where f
is the target of *this
.
if R
is void
, nothing is returned; otherwise, the return value of the call to f
is returned.
bad_function_call
if !this->empty()
. Otherwise, may through any exception thrown by the target function f
.
function<Signature, Allocator>&
function<Signature, Allocator>&
f1.swap(f2)
Will not throw.
const function<Signature1, Allocator1>&
const function<Signature2, Allocator2>&
This function must be left undefined.
The safe_bool
conversion opens a loophole whereby two function instances can be compared via ==
. This undefined void operator ==
closes the loophole and ensures a compile-time or link-time error.
const function<Signature1, Allocator1>&
const function<Signature2, Allocator2>&
This function must be left undefined.
The safe_bool
conversion opens a loophole whereby two function instances can be compared via !=
. This undefined void operator !=
closes the loophole and ensures a compile-time or link-time error.