Freigeben über


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)
   {
public:
   typedef Ret result_type;

   function();
   function(nullptr_t);
   function(const function& _Right);
   template<class Fty2>
      function(Fty2 fn);
   template<class Fty2, class Alloc>
       function (reference_wrapper<Fty2>, const Alloc& _Ax);
   template<class Fty2, class Alloc>
       void assign (Fty2, const Alloc& _Ax);
   template<class Fty2, class Alloc>
       assign (reference_wrapper<Fty2>, const Alloc& _Ax);
   function& operator=(nullptr_t);
   function& operator=(const function&);
   template<class Fty2>
      function& operator=(Fty2);
   template<class Fty2>
      function& operator=(reference_wrapper<Fty2>);
   void swap(function&);

   explicit operator bool() 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>
      void operator==(const Fty2&) const = delete;
   template<class Fty2>
      void operator!=(const Fty2&) const = delete;
};

Parameters

  • Fty
    The function type to wrap.

  • _Ax
    The allocator function.

Remarks

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.

Requirements

Header: <functional>

Namespace: std

See Also

Reference

mem_fn Function

reference_wrapper Class

Other Resources

<functional> Members