function Class
The document is archived and information here might be outdated

function Class

Wrapper for a callable object.

template<class Fty>
   class function  // Fty of type Ret(T1, T2, ..., TN)
   : public unary_function<T1, Ret>       // when Fty is Ret(T1)
   : public binary_function<T1, T2, Ret>  // when Fty is Ret(T1, T2)
   typedef Ret result_type;

   function(const function& right);
   template<class F>
      function(F fn);
   template<class F, class A>
      function(F fn, A ator);

   function& operator=(null_ptr_type);
   function& operator=(const function&);
   template<class Fty2>
      function& operator=(Fty2);
   template<class Fty2>
      function& operator=(reference_wrapper<Fty2>);
   void swap(function&);

   operator unspecified() const;
   result_type operator()(T1, T2, ....., TN) const;

   const std::type_info& target_type() const;
   template<class Fty2>
      Fty2 *target();
   template<class Fty2>
      const Fty2 *target() const;

   template<class Fty2>
      bool operator==(const Fty2&) const;  // undefined
   template<class Fty2>
      bool operator!=(const Fty2&) const;  // undefined


The function type to wrap.

The template class is a call wrapper whose call signature is Ret(T1, T2, ..., TN). You use it to enclose a variety of callable objects in a uniform wrapper.

Some member functions take an operand that names the desired target object. You can specify such an operand in several ways:

fn -- the callable object fn; after the call the function object holds a copy of fn

fnref -- the callable object named by fnref.get(); after the call the function object holds a reference to fnref.get()

right -- the callable object, if any, held by the function object right

npc -- a null pointer; after the call the function object is empty

In all cases, INVOKE(f, t1, t2, ..., tN), where f is the callable object and t1, t2, ..., tN are lvalues of types T1, T2, ..., TN respectively, must be well-formed and, if Ret is not void, convertible to Ret.

An empty function object does not hold a callable object or a reference to a callable object.

Header: <functional>

Namespace: std::tr1

© 2016 Microsoft