# 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.

bool `const Functor&`

`true` if `this->`target`<Functor>()` is non-NULL and `function_equal(*(this->target<Functor>()), f)`

const std::type_info&

`typeid` of the target function object, or `typeid(void)` if `this->`empty`()`.

Will not throw.

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
T1 If 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.

F
Allocator

F is a function object Callable from `this`, Allocator is an allocator. The copy constructor and destructor of Allocator shall not throw.

`*this` targets a copy of `f` if `f` is nonempty, or `this->`empty`()` if `f` is empty.

If memory allocation is required, the given allocator (or a copy of it) will be used to allocate that memory.

If `!this->`empty`()`, destroys the target of this.

const `functionN`&

If copy construction does not throw, `*this` targets a copy of `f`'s target, if it has one, or is empty if `f.`empty`()`. If copy construction does throw, `this->`empty`()`.

void `const `functionN`&`

Interchanges the targets of `*this` and `f`.

void

this->`empty`()

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.

bool `const Functor&`

`true` if `this->`target`<Functor>()` is non-NULL and `function_equal(*(this->target<Functor>()), f)`

const std::type_info&

`typeid` of the target function object, or `typeid(void)` if `this->`empty`()`.

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>&` ``functionN`<T1, T2, ..., TN>&`

`f1.`swap`(f2)`

bool `const `functionN`<T1, T2, ..., TN>&` `Functor`
bool `Functor` `const `functionN`<T1, T2, ..., TN>&`
bool `const `functionN`<T1, T2, ..., TN>&` ``reference_wrapper`<Functor>`
bool ``reference_wrapper`<Functor>` `const `functionN`<T1, T2, ..., TN>&`
void `const `functionN`<T1, T2, ..., TN>&` `const `functionN`<U1, U2, ..., UN>&`

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 `function_equal(*(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>&` `Functor`
bool `Functor` `const `functionN`<T1, T2, ..., TN>&`
bool `const `functionN`<T1, T2, ..., TN>&` ``reference_wrapper`<Functor>`
bool ``reference_wrapper`<Functor>` `const `functionN`<T1, T2, ..., TN>&`
void `const `functionN`<T1, T2, ..., TN>&` `const `functionN`<U1, U2, ..., UN>&`

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 `!function_equal(*(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)
functionN
<R, T1, T2, ..., TN>
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
T1 If 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.

F
Allocator

F is a function object Callable from `this`, Allocator is an allocator. The copy constructor and destructor of Allocator shall not throw.

`*this` targets a copy of `f` if `f` is nonempty, or `this->`empty`()` if `f` is empty.

If memory allocation is required, the given allocator (or a copy of it) will be used to allocate that memory.

If `!this->`empty`()`, destroys the target of `this`.

const `function`&

If copy construction does not throw, `*this` targets a copy of `f`'s target, if it has one, or is empty if `f.`empty`()`. If copy construction does throw, `this->`empty`()`.

const `function`&

If copy construction of the target of `f` does not throw, `*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. If copy construction does throw, `this->`empty`()`.

void `const `function`&`

Interchanges the targets of `*this` and `f`.

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.

bool `const Functor&`

`true` if `this->`target`<Functor>()` is non-NULL and `function_equal(*(this->target<Functor>()), f)`

const std::type_info&

`typeid` of the target function object, or `typeid(void)` if `this->`empty`()`.

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>&` ``function`<Signature>&`

`f1.`swap`(f2)`

bool `const `function`<Signature>&` `Functor`
bool `Functor` `const `function`<Signature>&`
bool `const `function`<Signature>&` ``reference_wrapper`<Functor>`
bool ``reference_wrapper`<Functor>` `const `function`<Signature>&`
void `const `function`<Signature1>&` `const `function`<Signature2>&`

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 `function_equals(*(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>&` `Functor`
bool `Functor` `const `function`<Signature>&`
bool `const `function`<Signature>&` ``reference_wrapper`<Functor>`
bool ``reference_wrapper`<Functor>` `const `function`<Signature>&`
void `const `function`<Signature1>&` `const `function`<Signature2>&`

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 `!function_equals(*(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 F&` `const G&`

Compare two function objects for equality.

`f == g`.

Only if `f == g` throws.