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.
bool
false
if this
has a target, and true
otherwise.
Will not throw.
Functor*
const Functor*
If this
stores a target of type
Functor
, returns the address of the
target. Otherwise, returns the NULL
pointer.
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
int
N
Lambda library support
result_type
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.
void
const functionN&
Interchanges the targets of *this
and f
.
Will not throw.
void
this->empty()
Will not throw.
bool
false
if this
has a target, and true
otherwise.
Will not throw.
safe_bool
A safe_bool
that evaluates false
in a boolean context when this->empty()
, and true
otherwise.
Will not throw.
bool
this->empty()
Will not throw.
Functor*
const Functor*
If this
stores a target of type
Functor
, returns the address of the
target. Otherwise, returns the NULL
pointer.
Will not throw.
result_type
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
.
void
functionN<T1, T2, ..., TN, Allocator>&
functionN<T1, T2, ..., TN, Allocator>&
f1.swap(f2)
Will not throw.
bool
const functionN<T1, T2, ..., TN, Allocator>&
Functor
bool
Functor
const functionN<T1, T2, ..., TN, Allocator>&
bool
const functionN<T1, T2, ..., TN, Allocator>&
reference_wrapper<Functor>
bool
reference_wrapper<Functor>
const functionN<T1, T2, ..., TN, Allocator>&
void
const functionN<T1, T2, ..., TN, Allocator1>&
const functionN<U1, U2, ..., UN, Allocator2>&
True when f
stores an object of
type Functor
and one of the following conditions applies:
g
is of type
reference_wrapper<Functor>
and f.target<Functor>() == g.get_pointer()
.
g
is not of type
reference_wrapper<Functor>
and *(f.target<Functor>()) ==
g
.
functionN
objects are not
EqualityComparable.
The safe_bool
conversion
opens a loophole whereby two functionN
instances can be compared via ==
, although this
is not feasible to implement. The undefined void
operator==
closes the loophole and ensures a
compile-time or link-time error.
bool
const functionN<T1, T2, ..., TN, Allocator>&
Functor
bool
Functor
const functionN<T1, T2, ..., TN, Allocator>&
bool
const functionN<T1, T2, ..., TN, Allocator>&
reference_wrapper<Functor>
bool
reference_wrapper<Functor>
const functionN<T1, T2, ..., TN, Allocator>&
void
const functionN<T1, T2, ..., TN, Allocator1>&
const functionN<U1, U2, ..., UN, Allocator2>&
True when f
does not store an
object of type Functor
or it stores an object of
type Functor
and one of the following conditions
applies:
g
is of type
reference_wrapper<Functor>
and f.target<Functor>() != g.get_pointer()
.
g
is not of type
reference_wrapper<Functor>
and *(f.target<Functor>()) !=
g
.
functionN
objects are not
EqualityComparable.
The safe_bool
conversion
opens a loophole whereby two functionN
instances can be compared via !=
, although this
is not feasible to implement. The undefined void
operator!=
closes the loophole and ensures a
compile-time or link-time error.
Function type R (T1, T2, ..., TN)
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
int
N
Lambda library support
result_type
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.
void
const function&
Interchanges the targets of *this
and f
.
Will not throw.
void
this->empty()
Will not throw.
bool
false
if this
has a target, and true
otherwise.
Will not throw.
safe_bool
A safe_bool
that evaluates false
in a boolean context when this->empty()
, and true
otherwise.
Will not throw.
bool
this->empty()
Will not throw.
Functor*
const Functor*
If this
stores a target of type
Functor
, returns the address of the
target. Otherwise, returns the NULL
pointer.
Will not throw.
result_type
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
.
void
function<Signature, Allocator>&
function<Signature, Allocator>&
f1.swap(f2)
Will not throw.
bool
const function<Signature, Allocator>&
Functor
bool
Functor
const function<Signature, Allocator>&
bool
const function<Signature, Allocator>&
reference_wrapper<Functor>
bool
reference_wrapper<Functor>
const function<Signature, Allocator>&
void
const function<Signature1, Allocator1>&
const function<Signature2, Allocator2>&
True when f
stores an object of
type Functor
and one of the following conditions applies:
g
is of type
reference_wrapper<Functor>
and f.target<Functor>() == g.get_pointer()
.
g
is not of type
reference_wrapper<Functor>
and *(f.target<Functor>()) ==
g
.
function
objects are not
EqualityComparable.
The safe_bool
conversion
opens a loophole whereby two function
instances can be compared via ==
, although this
is not feasible to implement. The undefined void
operator==
closes the loophole and ensures a
compile-time or link-time error.
bool
const function<Signature, Allocator>&
Functor
bool
Functor
const function<Signature, Allocator>&
bool
const function<Signature, Allocator>&
reference_wrapper<Functor>
bool
reference_wrapper<Functor>
const function<Signature, Allocator>&
void
const function<Signature1, Allocator1>&
const function<Signature2, Allocator2>&
True when f
does not store an
object of type Functor
or it stores an object of
type Functor
and one of the following conditions
applies:
g
is of type
reference_wrapper<Functor>
and f.target<Functor>() != g.get_pointer()
.
g
is not of type
reference_wrapper<Functor>
and *(f.target<Functor>()) !=
g
.
function
objects are not
EqualityComparable.
The safe_bool
conversion
opens a loophole whereby two function
instances can be compared via !=
, although this
is not feasible to implement. The undefined void
operator!=
closes the loophole and ensures a
compile-time or link-time error.