Boost.Function Reference Manual

Header <boost/function.hpp> synopsis

Here MAX_ARGS is an implementation-defined constant that defines the maximum number of function arguments supported by Boost.Function and will be at least 10. The MAX_ARGS constant referred to in this document need not have any direct representation in the library.

namespace boost {
  class function_base  // Deprecated
  {
    bool empty() const;
  };

  // For N in [0, MAX_ARGS]
  template<typename Signature,
           typename Arg1,
	   typename Arg2,
           ...
           typename ArgN,
	   typename Allocator = std::allocator<void> >
  class functionN : public function_base
  {
    typedef implementation-defined safe_bool;

  public:
    typedef ResultType result_type; // [1]
    typedef Allocator  allocator_type;

    typedef Arg1 argument_type;        // If N == 1

    typedef Arg1 first_argument_type;  // If N == 2
    typedef Arg2 second_argument_type; // If N == 2

    typedef Arg1 arg1_type;
    typedef Arg2 arg2_type;
             .
             .
             .
    typedef ArgN argN_type;

    enum { arity = N };

    // Construction
    explicit functionN();
    functionN(const functionN&);
    template<typename F> functionN(F);
    template<typename F> functionN(reference_wrapper<F>);
    
    // Assignment
    functionN& operator=(const functionN&);
    template<typename F> functionN& operator=(F);
    template<typename F> functionN& operator=(reference_wrapper<F>);
    void swap(functionN&);
    void clear();

    // Boolean context
    operator safe_bool() const;
    bool operator!() const;

    // Invocation
    result_type operator()(Arg1 a1, Arg2 a2, ..., ArgN aN) const;
  };

  template<typename ResultType,
           typename Arg1,
	   typename Arg2,
           ...
	   typename ArgN,
           typename Allocator>
  void swap(functionN<ResultType, Arg1, Arg2, ..., ArgN, Allocator>&,
            functionN<ResultType, Arg1, Arg2, ..., ArgN, Allocator>&);

  // For any N in [0, MAX_ARGS]
  template<typename Signature, // Function type: ResultType (Arg1, Arg2, ..., ArgN)
	   typename Allocator = std::allocator<void> >
  class function : public functionN<ResultType, Arg1, Arg2, ..., ArgN, Allocator>
  {
    // Construction
    function();
    function(const function&);
    function(const functionN<ResultType, Arg1, Arg2, ..., ArgN, Allocator>&);
    template<typename F> functionN(F);
    
    // Assignment
    function& operator=(const function&);
    function& operator=(const functionN<ResultType, Arg1, Arg2, ..., ArgN, Allocator>&);
    template<typename F> function& operator=(F);
  };

  template<typename Signature, typename Allocator>
  void swap(function<Signature, Allocator>&,
            function<Signature, Allocator>&);
}	   

Definitions

Class function_base

Class function_base is the common base class for all Boost.Function objects. Objects of type function_base may not be created directly.

Note: the use of this class by users is deprecated. This class will become an implementation detail in the future.

bool empty() const

Class template functionN

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 and f refers to the implicit object parameter.

explicit functionN();

functionN(const functionN& g);

template<typename F> functionN(F g);

template<typename F> functionN(reference_wrapper<F> g);

functionN& operator=(const functionN& g);

template<typename F> functionN& operator=(F g);

template<typename F> functionN& operator=(reference_wrapper<F> g);

void swap(functionN& g);

void clear();

operator safe_bool() const

bool operator!() const

result_type operator()(Arg1 a1, Arg2 a2, ..., ArgN aN) const;

Class template function

Class template function is a thin wrapper around the numbered class templates function0, function1, etc. It accepts up to MAX_ARGS arguments, but when passed N arguments it will derive from functionN specialized 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.

Operations

template<typename ResultType,
         typename Arg1,
	 typename Arg2,
         ...
	 typename ArgN,
         typename Allocator>
void swap(functionN<ResultType, Arg1, Arg2, ..., ArgN, Allocator>& f,
          functionN<ResultType, Arg1, Arg2, ..., ArgN, Allocator>& g);

template<typename Signature, typename Allocator>
void swap(function<Signature, Allocator>& f,
          function<Signature, Allocator>& g);

[1] On compilers not supporting void returns, when the ReturnType is void, the result_type of a Boost.Function object is implementation-defined.


Douglas Gregor
Last modified: Fri Sep 6 14:46:50 EDT 2002