Class template functionN
boost::functionN — A set of generalized function pointers that can be used for callbacks or wrapping function objects.
Synopsis
template<typename R, typename T1, typename T2, ..., typename TN> class functionN : public function_base { public: // types typedef R result_type; typedef T1 argument_type; // If N == 1 typedef T1 first_argument_type; // If N == 2 typedef T2 second_argument_type; // If N == 2 typedef T1 arg1_type; typedef T2 arg2_type; . . . typedef TN argN_type; // static constants static const int arity = N; // Lambda library support template<typename Args> struct sig { // types typedef result_type type; }; // construct/copy/destruct functionN(); functionN(const functionN&); template<typename F> functionN(F); template<typename F, typename Allocator> functionN(F, Allocator); functionN& operator=(const functionN&); ~functionN(); // modifiers void swap(const functionN&); void clear(); // capacity bool empty() const; operator safe_bool() const; bool operator!() const; // target access template<typename Functor> Functor* target(); template<typename Functor> const Functor* target() const; template<typename Functor> bool contains(const Functor&) const; const std::type_info& target_type() const; // invocation result_type operator()(arg1_type, arg2_type, ..., argN_type) const; }; // specialized algorithms template<typename T1, typename T2, ..., typename TN> void swap(functionN<T1, T2, ..., TN>&, functionN<T1, T2, ..., TN>&); // comparison operators template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator==(const functionN<T1, T2, ..., TN>&, Functor); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator==(Functor, const functionN<T1, T2, ..., TN>&); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator==(const functionN<T1, T2, ..., TN>&, reference_wrapper<Functor>); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator==(reference_wrapper<Functor>, const functionN<T1, T2, ..., TN>&); template<typename T1, typename T2, ..., typename TN, typename U1, typename U2, ..., typename UN> void operator==(const functionN<T1, T2, ..., TN>&, const functionN<U1, U2, ..., UN>&); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator!=(const functionN<T1, T2, ..., TN>&, Functor); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator!=(Functor, const functionN<T1, T2, ..., TN>&); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator!=(const functionN<T1, T2, ..., TN>&, reference_wrapper<Functor>); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator!=(reference_wrapper<Functor>, const functionN<T1, T2, ..., TN>&); template<typename T1, typename T2, ..., typename TN, typename U1, typename U2, ..., typename UN> void operator!=(const functionN<T1, T2, ..., TN>&, const functionN<U1, U2, ..., UN>&);
Description
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.
functionN
public
construct/copy/destruct
-
functionN();
Postconditions:
this->empty()Throws:
Will not throw. -
functionN(const functionN& f);
Postconditions:
Contains a copy of the f's target, if it has one, or is empty iff.empty().Throws:
Will not throw unless copying the target of fthrows. -
template<typename F> functionN(F f);
Requires:
F is a function object Callable from this.Postconditions:
*thistargets a copy offiffis nonempty, orthis->empty()iffis empty. -
template<typename F, typename Allocator> functionN(F f, Allocator alloc);
Requires:
F is a function object Callable from this, Allocator is an allocator. The copy constructor and destructor of Allocator shall not throw.Postconditions:
*thistargets a copy offiffis nonempty, orthis->empty()iffis empty.Effects:
If memory allocation is required, the given allocator (or a copy of it) will be used to allocate that memory. -
functionN& operator=(const functionN& f);
-
~functionN();
Effects:
If !this->empty(), destroys the target of this.
functionN capacity
-
bool empty() const;
Returns:
falseifthishas a target, andtrueotherwise.Throws:
Will not throw. -
operator safe_bool() const;
Returns:
A safe_boolthat evaluatesfalsein a boolean context whenthis->empty(), andtrueotherwise.Throws:
Will not throw. -
bool operator!() const;
Returns:
this->empty()Throws:
Will not throw.
functionN target access
-
template<typename Functor> Functor* target(); template<typename Functor> const Functor* target() const;
Returns:
If thisstores a target of typeFunctor, returns the address of the target. Otherwise, returns the NULL pointer.Throws:
Will not throw. -
template<typename Functor> bool contains(const Functor& f) const;
Returns:
trueifthis->target<Functor>()is non-NULL andfunction_equal(*(this->target<Functor>()), f) -
const std::type_info& target_type() const;
Returns:
typeidof the target function object, ortypeid(void)ifthis->empty().Throws:
Will not throw.
functionN invocation
-
result_type operator()(arg1_type a1, arg2_type a2, ..., argN_type aN) const;
Effects:
f(a1, a2, ..., aN), wherefis the target of*this.Returns:
if Risvoid, nothing is returned; otherwise, the return value of the call tofis returned.Throws:
bad_function_callifthis->empty(). Otherwise, may through any exception thrown by the target functionf.
functionN comparison operators
-
template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator==(const functionN<T1, T2, ..., TN>& f, Functor g); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator==(Functor g, const functionN<T1, T2, ..., TN>& f); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator==(const functionN<T1, T2, ..., TN>& f, reference_wrapper<Functor> g); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator==(reference_wrapper<Functor> g, const functionN<T1, T2, ..., TN>& f); template<typename T1, typename T2, ..., typename TN, typename U1, typename U2, ..., typename UN> void operator==(const functionN<T1, T2, ..., TN>& f1, const functionN<U1, U2, ..., UN>& f2);
Returns:
True when fstores an object of typeFunctorand one of the following conditions applies:-
gis of typereference_wrapper<Functor>andf.target<Functor>() == g.get_pointer(). -
gis not of typereference_wrapper<Functor>andfunction_equal(*(f.target<Functor>()), g).
Notes:
functionNobjects are not EqualityComparable.Rationale:
The safe_boolconversion opens a loophole whereby twofunctionNinstances can be compared via==, although this is not feasible to implement. The undefinedvoid operator==closes the loophole and ensures a compile-time or link-time error. -
-
template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator!=(const functionN<T1, T2, ..., TN>& f, Functor g); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator!=(Functor g, const functionN<T1, T2, ..., TN>& f); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator!=(const functionN<T1, T2, ..., TN>& f, reference_wrapper<Functor> g); template<typename T1, typename T2, ..., typename TN, typename Functor> bool operator!=(reference_wrapper<Functor> g, const functionN<T1, T2, ..., TN>& f); template<typename T1, typename T2, ..., typename TN, typename U1, typename U2, ..., typename UN> void operator!=(const functionN<T1, T2, ..., TN>& f1, const functionN<U1, U2, ..., UN>& f2);
Returns:
True when fdoes not store an object of typeFunctoror it stores an object of typeFunctorand one of the following conditions applies:-
gis of typereference_wrapper<Functor>andf.target<Functor>() != g.get_pointer(). -
gis not of typereference_wrapper<Functor>and!function_equal(*(f.target<Functor>()), g).
Notes:
functionNobjects are not EqualityComparable.Rationale:
The safe_boolconversion opens a loophole whereby twofunctionNinstances can be compared via!=, although this is not feasible to implement. The undefinedvoid operator!=closes the loophole and ensures a compile-time or link-time error. -
