<functional>

Description
Synopsis
Classes
Functions
Operators
Structures
Objects

Description

Include the STL standard header <functional> to define several templates that help construct function objects, objects of a type that defines operator(). A function object can thus be a function pointer, but in the more general case the object can store additional information that can be used during a function call.

Note:
Additional functionality has been added to this header for TR1. To enable this functionality, you must define the macro __IBMCPP_TR1__ .

The following terminology applies to features added with TR1:

A call signature is the name of a return type followed by a parenthesized comma-separated list of zero or more argument types.

A call wrapper is an object of a call wrapper type.

A call wrapper type is a type that holds a callable object and supports a call operation that forwards to that object.

A callable object is an object of a callable type.

A callable type is a pointer to function, a pointer to member function, a pointer to member data, or a class type whose objects can appear immediately to the left of a function call operator.

A target object is the callable object held by a call wrapper object.

The pseudo-function INVOKE(f, t1, t2, ..., tN) means:

The pseudo-function INVOKE(f, t1, t2, ..., tN, R) means INVOKE(f, t1, t2, ..., tN) implicitly converted to R.

If a call wrapper has a weak result type the type of its member type result_type is based on the type T of the wrapper's target object:

Every call wrapper has a copy constructor. A simple call wrapper is a call wrapper that has an assignment operator and whose copy constructor and assignment operator do not throw exceptions. A forwarding call wrapper is a call wrapper that can be called with an argument list t1, t2, ..., tN where each ti is an lvalue.

The call wrappers defined in this header support function call operators with arguments of types T1, T2, ..., TN, where 0 <= N <= NMAX. In this implementation the value of NMAX is 10. By default, the compiler generates code that enables function call operators with up to 3 arguments, thus, N = 3. When more arguments is required, _NARGS_CONST macro can be defined to value greater than 3. However, its value has to be within [0, 10]. This macro has to be used carefully because the compile time increases exponentially.

Synopsis

namespace std {
template<class Arg, class Result>
    struct unary_function;
template<class Arg1, class Arg2, class Result>
    struct binary_function;
template<class Ty>
    struct plus;
template<class Ty>
    struct minus;
template<class Ty>
    struct multiplies;
template<class Ty>
    struct divides;
template<class Ty>
    struct modulus;
template<class Ty>
    struct negate;
template<class Ty>
    struct equal_to;
template<class Ty>
    struct not_equal_to;
template<class Ty>
    struct greater;
template<class Ty>
    struct less;
template<class Ty>
    struct greater_equal;
template<class Ty>
    struct less_equal;
template<class Ty>
    struct logical_and;
template<class Ty>
    struct logical_or;
template<class Ty>
    struct logical_not;
template<class Fn1>
    struct unary_negate;
template<class Fn2>
    struct binary_negate;
template<class Fn2>
    class binder1st;
template<class Fn2>
    class binder2nd;
template<class Arg, class Result>
    class pointer_to_unary_function;
template<class Arg1, class Arg2, class Result>
    class pointer_to_binary_function;
template<class Result, class Ty>
    struct mem_fun_t;
template<class Result, class Ty, class Arg>
    struct mem_fun1_t;
template<class Result, class Ty>
    struct const_mem_fun_t;
template<class Result, class Ty, class Arg>
    struct const_mem_fun1_t;
template<class Result, class Ty>
    struct mem_fun_ref_t;
template<class Result, class Ty, class Arg>
    struct mem_fun1_ref_t;
template<class Result, class Ty>
    struct const_mem_fun_ref_t;
template<class Result, class Ty, class Arg>
    struct const_mem_fun1_ref_t;

// TEMPLATE FUNCTIONS
template<class Fn1>
    unary_negate<Fn1> not1(const Fn1& func);
template<class Fn2>
    binary_negate<Fn2> not2(const Fn2& func);
template<class Fn2, class Ty>
    binder1st<Fn2> bind1st(const Fn2& func, const Ty& left);
template<class Fn2, class Ty>
    binder2nd<Fn2> bind2nd(const Fn2& func, const Ty& left);
template<class Arg, class Result>
    pointer_to_unary_function<Arg, Result>
        ptr_fun(Result (*)(Arg));
template<class Arg1, class Arg2, class Result>
    pointer_to_binary_function<Arg1, Arg2, Result>
        ptr_fun(Result (*)(Arg1, Arg2));
template<class Result, class Ty>
    mem_fun_t<Result, Ty> mem_fun(Result (Ty::*pm)());
template<class Result, class Ty, class Arg>
    mem_fun1_t<Result, Ty, Arg> mem_fun(Result (Ty::*pm)(Arg left));
template<class Result, class Ty>
    const_mem_fun_t<Result, Ty> mem_fun(Result (Ty::*pm)() const);
template<class Result, class Ty, class Arg>
    const_mem_fun1_t<Result, Ty, Arg> mem_fun(Result (Ty::*pm)(Arg left) const);
template<class Result, class Ty>
    mem_fun_ref_t<Result, Ty> mem_fun_ref(Result (Ty::*pm)());
template<class Result, class Ty, class Arg>
    mem_fun1_ref_t<Result, Ty, Arg>
        mem_fun_ref(Result (Ty::*pm)(Arg left));
template<class Result, class Ty>
    const_mem_fun_ref_t<Result, Ty> mem_fun_ref(Result (Ty::*pm)() const);
template<class Result, class Ty, class Arg>
    const_mem_fun1_ref_t<Result, Ty, Arg>
        mem_fun_ref(Result (Ty::*pm)(Arg left) const);
#ifdef __IBMCPP_TR1__

namespace tr1 {
// TEMPLATE STRUCT hash
template <class Ty>
        struct hash;

// REFERENCE WRAPPERS 
template <class Ty> 
    reference_wrapper<Ty>
        ref(Ty&);
template <class Ty> 
    reference_wrapper<Ty>
        ref(reference_wrapper<Ty>&);
template <class Ty> 
    reference_wrapper<const Ty>
        cref(const Ty&);
template <class Ty> 
    reference_wrapper<const Ty>
        cref(const reference_wrapper<Ty>&);
template <class Ty>
    struct reference_wrapper;

// FUNCTION OBJECT RETURN TYPES
template <class Ty>
    struct result_of;

// ENHANCED MEMBER POINTER ADAPTER
template <class Ret, class Ty>
    unspecified mem_fn(Ret Ty::*);

// FUNCTION OBJECT WRAPPERS
class bad_function_call;
template<class Fty>
    class function;
template<class Fty>
    void swap(function<Fty>& f1,
        function<Fty>& f2);
template<class Fty>
    bool operator!=(const function<Fty>&,
        null_ptr_type);
template<class Fty>
    bool operator!=(null_ptr_type,
        const function<Fty>&);
template<class Fty>
    bool operator==(const function<Fty>&,
        null_ptr_type);
template<class Fty>
    bool operator==(null_ptr_type,
        const function<Fty>&);

// ENHANCED BINDERS
template <class Fty, class T1, class T2, ..., class TN>
    unspecified bind(Fty, T1, T2, ..., TN);
template <class Ret, class Fty, class T1, class T2, ..., class TN>
    unspecified bind(Fty, T1, T2, ..., TN);
template <class Ret, class Ty, class T1, class T2, ..., class TN>
    unspecified bind(Ret Ty::*, T1, T2, ..., TN);

template <class Ty>
    struct is_bind_expression;
template <class Ty>
    struct is_placeholder;

namespace placeholders {
    extern unspecified _1;  // _2, _3, ... _M
        } // namespace placeholders
    } //namespace tr1
} //namespace std

#endif /* def __IBMCPP_TR1__ */

Classes

bad_function_call
binary_function
binary_negate
binder1st
binder2nd
const_mem_fun_t
const_mem_fun_ref_t
const_mem_fun1_t
const_mem_fun1_ref_t
divides
equal_to
function
greater
greater_equal
hash
less
less_equal
logical_and
logical_not
logical_or
mem_fun_t
mem_fun_ref_t
mem_fun1_t
mem_fun1_ref_t
minus
modulus
multiplies
negate
not_equal_to
plus
pointer_to_binary_function
pointer_to_unary_function
reference_wrapper
result_of
unary_function
unary_negate

bad_function_call

class bad_function_call
    : public std::exception {
    };

[Added with TR1]

The class describes an exception thrown to indicate that a call to operator() on a function object failed because the object was empty.

binary_function

template<class Arg1, class Arg2, class Result>
    struct binary_function {
    typedef Arg1 first_argument_type;
    typedef Arg2 second_argument_type;
    typedef Result result_type;
    };

The template class serves as a base for classes that define a member function of the form:

result_type operator()(const first_argument_type&,
    const second_argument_type&) const

or a similar form taking two arguments.

Hence, all such binary functions can refer to their first argument type as first_argument_type, their second argument type as second_argument_type, and their return type as result_type.

binary_negate

template<class Fn2>
    class binary_negate
        : public binary_function<
            typename Fn2::first_argument_type,
            typename Fn2::second_argument_type, bool> {
public:
    explicit binary_negate(const Fn2& func);
    bool operator()(
        const typename Fn2::first_argument_type& left,
        const typename Fn2::second_argument_type& right) const;
    };

The template class stores a copy of func, which must be a binary function object. It defines its member function operator() as returning !func(left, right).

binder1st

template<class Fn2>
    class binder1st
        : public unary_function<
            typename Fn2::second_argument_type,
            typename Fn2::result_type> {
public:
    typedef typename Fn2::second_argument_type argument_type;
    typedef typename Fn2::result_type result_type;
    binder1st(const Fn2& func,
        const typename Fn2::first_argument_type& left);
    result_type operator()(const argument_type& right) const;
protected:
    Fn2 op;
    typename Fn2::first_argument_type value;
    };

The template class stores a copy of func, which must be a binary function object, in op, and a copy of left in value. It defines its member function operator() as returning op(value, right).

binder2nd

template<class Fn2>
    class binder2nd
        : public unary_function<
            typename Fn2::first_argument_type,
            typename Fn2::result_type> {
public:
    typedef typename Fn2::first_argument_type argument_type;
    typedef typename Fn2::result_type result_type;
    binder2nd(const Fn2& func,
        const typename Fn2::second_argument_type& right);
    result_type operator()(const argument_type& left) const;
protected:
    Fn2 op;
    typename Fn2::second_argument_type value;
    };

The template class stores a copy of func, which must be a binary function object, in op, and a copy of right in value. It defines its member function operator() as returning op(left, value).

const_mem_fun_t

template<class Result, class Ty>
    struct const_mem_fun_t
        : public unary_function<const Ty *, Result> {
    explicit const_mem_fun_t(Result (Ty::*pm)() const);
    Result operator()(const Ty *pleft) const;
    };

The template class stores a copy of pm, which must be a pointer to a member function of class Ty, in a private member object. It defines its member function operator() as returning (pleft->*pm)() const.

const_mem_fun_ref_t

template<class Result, class Ty>
    struct const_mem_fun_ref_t
        : public unary_function<Ty, Result> {
    explicit const_mem_fun_t(Result (Ty::*pm)() const);
    Result operator()(const Ty& left) const;
    };

The template class stores a copy of pm, which must be a pointer to a member function of class Ty, in a private member object. It defines its member function operator() as returning (left.*Pm)() const.

const_mem_fun1_t

template<class Result, class Ty, class Arg>
    struct const_mem_fun1_t
        : public binary_function<Ty *, Arg, Result> {
    explicit const_mem_fun1_t(Result (Ty::*pm)(Arg) const);
    Result operator()(const Ty *pleft, Arg right) const;
    };

The template class stores a copy of pm, which must be a pointer to a member function of class Ty, in a private member object. It defines its member function operator() as returning (pleft->*pm)(right) const.

const_mem_fun1_ref_t

template<class Result, class Ty, class Arg>
    struct const_mem_fun1_ref_t
        : public binary_function<Ty, Arg, Result> {
    explicit const_mem_fun1_ref_t(Result (Ty::*pm)(Arg) const);
    Result operator()(const Ty& left, Arg right) const;
    };

The template class stores a copy of pm, which must be a pointer to a member function of class Ty, in a private member object. It defines its member function operator() as returning (left.*pm)(right) const.

divides

template<class Ty>
    struct divides : public binary_function<Ty, Ty, Ty> {
    Ty operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left/ right.

equal_to

template<class Ty>
    struct equal_to
        : public binary_function<Ty, Ty, bool> {
    bool operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left == right.

function

Description
Synopsis
Constructor
function::function
Types
function::result_type
function::target
Member functions
function::operator()
function::swap
function::target_type
Operators
function::operator=
function::operator==
function::operator!=
function::operator unspecified
Description

[Added with TR1]

The template class is a call wrapper whose call signature is Ret(T1, T2, ..., TN).

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

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.

Synopsis
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(null_ptr_type);
    function(const function&);
    template<class Fty2>
        function(Fty2);
    template<class Fty2>
        function(reference_wrapper<Fty2>);

    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;

private:
    template<class Fty2>
      bool operator==(const Fty2&) const;  // not defined
     template<class Fty2>
      bool operator!=(const Fty2&) const;  // not defined
      };
Constructor
function::function

function();
function(null_ptr_type npc);
function(const function& right);
template<class F>
    function(Fty fn);
template<class F>
    function(reference_wrapper<Fty> fnref);

The first two constructors construct an empty function object. The other constructors construct a function object that holds the callable object passed as the operand.

Types
function::result_type

typedef Ret result_type;

The typedef is a synonym for the type Ret in the template's call signature.

function::target

template<class Fty2> Fty2 *target();
template<class Fty2> const Fty2 *target() const;

The type Fty2 must be callable for the argument types T1, T2, ..., TN and the return type Ret. If target_type() == typeid(Fty2), the member template function returns the address of the target object; otherwise, it returns 0.

A type Fty2 is callable for the argument types T1, T2, ..., TN and the return type Ret if, for lvalues fn, t1, t2, ..., tN of types Fty2, T1, T2, ..., TN, respectively, INVOKE (fn, t1, t2, ..., tN) is well-formed and, if Ret is not void, convertible to Ret.

Member functions
function::operator()

result_type operator()(T1 t1, T2 t2, ..., TN tN);

The member function returns INVOKE (fn, t1, t2, ..., tN, Ret), where fn is the target object stored in *this.

function::swap

void swap(function& right);

The member function swaps the target objects between *this and right. It does so in constant time and throws no exceptions.

function::target_type

const std::type_info& target_type() const;

The member function returns typeid(void) if *this is empty, otherwise it returns typeid(T), where T is the type of the target object.

Operators
function::operator=

function& operator=(null_ptr_type npc);
function& operator=(const function& right);
template<class Fty>
    function& operator=(Fty fn);
template<class Fty>
    function& operator=(reference_wrapper<Fty> fnref);

The operators each replace the callable object held by *this with the callable object passed as the operand.

function::operator==

template<class Fty2>
    bool operator==(const function<Fty2>&);

The operator is private so that it cannot be called.

function::operator!=

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

The operator is private so that it cannot be called.

function::operator unspecified

operator unspecified();

The operator returns a value that is convertible to bool with a true value only if the object is not empty.

greater

template<class Ty>
    struct greater : public binary_function<Ty, Ty, bool> {
    bool operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left > right. The member function defines a total ordering, even if Ty is an object pointer type.

greater_equal

template<class Ty>
    struct greater_equal
        : public binary_function<Ty, Ty, bool> {
    bool operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left >= right. The member function defines a total ordering if Ty is an object pointer type.

hash

template <class Ty>
    struct hash 
        : public unary_function<Ty, size_t> {
    size_t operator()(Ty val) const;
    };

The template class defines its member function as returning a value uniquely determined by val. The member function defines a hash function, suitable for mapping values of type Ty to a distribution of index values. Ty may be any scalar type, string, wstring, or, beginning with C++0x, u16string, or u32string.

less

template<class Ty>
    struct less : public binary_function<Ty, Ty, bool> {
    bool operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left < right. The member function defines a total ordering if Ty is an object pointer type.

less_equal

template<class Ty>
    struct less_equal
        : public binary_function<Ty, Ty, bool> {
    bool operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left <= right. The member function defines a total ordering, even if Ty is an object pointer type.

logical_and

template<class Ty>
    struct logical_and
        : public binary_function<Ty, Ty, bool> {
    bool operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left && right.

logical_not

template<class Ty>
    struct logical_not : public unary_function<Ty, bool> {
    bool operator()(const Ty& left) const;
    };

The template class defines its member function as returning !left.

logical_or

template<class Ty>
    struct logical_or
        : public binary_function<Ty, Ty, bool> {
    bool operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left || right.

mem_fun_t

template<class Result, class Ty>
    struct mem_fun_t : public unary_function<Ty *, Result> {
    explicit mem_fun_t(Result (Ty::*pm)());
    Result operator()(Ty *pleft) const;
    };

The template class stores a copy of pm, which must be a pointer to a member function of class Ty, in a private member object. It defines its member function operator() as returning (pleft->*pm)().

mem_fun_ref_t

template<class Result, class Ty>
    struct mem_fun_ref_t
        : public unary_function<Ty, Result> {
    explicit mem_fun_t(Result (Ty::*pm)());
    Result operator()(Ty& left) const;
    };

The template class stores a copy of pm, which must be a pointer to a member function of class Ty, in a private member object. It defines its member function operator() as returning (left.*Pm)().

mem_fun1_t

template<class Result, class Ty, class Arg>
    struct mem_fun1_t
        : public binary_function<Ty *, Arg, Result> {
    explicit mem_fun1_t(Result (Ty::*pm)(Arg));
    Result operator()(Ty *pleft, Arg right) const;
    };

The template class stores a copy of pm, which must be a pointer to a member function of class Ty, in a private member object. It defines its member function operator() as returning (pleft->*pm)(right).

mem_fun1_ref_t

template<class Result, class Ty, class Arg>
    struct mem_fun1_ref_t
        : public binary_function<Ty, Arg, Result> {
    explicit mem_fun1_ref_t(Result (Ty::*pm)(Arg));
    Result operator()(Ty& left, Arg right) const;
    };

The template class stores a copy of pm, which must be a pointer to a member function of class Ty, in a private member object. It defines its member function operator() as returning (left.*pm)(right).

minus

template<class Ty>
    struct minus : public binary_function<Ty, Ty, Ty> {
    Ty operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left - right.

modulus

template<class Ty>
    struct modulus : public binary_function<Ty, Ty, Ty> {
    Ty operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left % right.

multiplies

template<class Ty>
    struct multiplies : public binary_function<Ty, Ty, Ty> {
    Ty operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left * right.

negate

template<class Ty>
    struct negate : public unary_function<Ty, Ty> {
    Ty operator()(const Ty& left) const;
    };

The template class defines its member function as returning -left.

not_equal_to

template<class Ty>
    struct not_equal_to
        : public binary_function<Ty, Ty, bool> {
    bool operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left != right.

plus

template<class Ty>
    struct plus : public binary_function<Ty, Ty, Ty> {
    Ty operator()(const Ty& left, const Ty& right) const;
    };

The template class defines its member function as returning left + right.

pointer_to_binary_function

template<class Arg1, class Arg2, class Result>
    class pointer_to_binary_function
        : public binary_function<Arg1, Arg2, Result> {
public:
    explicit pointer_to_binary_function(
        Result (*pfunc)(Arg1, Arg2));
    Result operator()(const Arg1 left, const Arg2 right) const;
    };

The template class stores a copy of pfunc. It defines its member function operator() as returning (*pfunc)(left, right).

pointer_to_unary_function

template<class Arg, class Result>
    class pointer_to_unary_function
        : public unary_function<Arg, Result> {
public:
    explicit pointer_to_unary_function(
        Result (*pfunc)(Arg));
    Result operator()(const Arg left) const;
    };

The template class stores a copy of pfunc. It defines its member function operator() as returning (*pfunc)(left).

reference_wrapper

Description
Synopsis
Constructor
reference_wrapper::reference_wrapper
Types
reference_wrapper::result_type
reference_wrapper::type
Member functions
reference_wrapper::get
Operators
reference_wrapper::operator ()
reference_wrapper::operator Ty&
Description

[Added with TR1]

A reference_wrapper<Ty> is copy constructible and assignable, and holds a pointer that points to an object of type Ty.

A specialization reference_wrapper<Ty> is derived from std::unary_function<T1, Ret> (hence defining the nested type result_type as a synonym for Ret and the nested type argument_type as a synonym for T1) only if the type Ty is:

A specialization reference_wrapper<Ty> is derived from std::binary_function<T1, T2, Ret> (hence defining the nested type result_type as a synonym for Ret, the nested type first_argument_type as a synonym for T1, and the nested type second_argument_type as a synonym for T2) only if the type Ty is:

Synopsis
template<class Ty>
    class reference_wrapper
    : public unary_function<T1, Ret>        // see below
    : public binary_function<T1, T2, Ret>   // see below
    {
public:
    typedef Ty type;
    typedef T0 result_type;                 // see below

    explicit reference_wrapper(Ty&);

    Ty& get() const;
    operator Ty&() const;
    template<class T1, class T2, ..., class TN>
        typename result_of<T(T1, T2, ..., TN)>::type
        operator()(T1&, T2&, ..., TN&);

private:
    Ty *ptr; // exposition only
    };
Constructor
reference_wrapper::reference_wrapper

explicit reference_wrapper(Ty& val);

The constructor sets the stored value ptr to &val.

Types
reference_wrapper::result_type

typedef T0 result_type;

The typedef is a synonym for the (weak result type) of a wrapped callable object.

reference_wrapper::type

typedef Ty type;

The typedef is a synonym for the template argument Ty.

Member functions
reference_wrapper::get

Ty& get() const;

The member function returns INVOKE (get(), t1, t2, ..., tN).

Operators
reference_wrapper::operator ()

template<class T1, class T2, ..., class TN>
    typename result_of<T(T1, T2, ..., TN)>::type
    operator()(T1& t1, T2& t2, ..., TN& tN);

The template member operator returns INVOKE (get(), t1, t2, ..., tN).

reference_wrapper::operator Ty&

operator Ty&() const;

The member operator returns *ptr.

result_of

template<class Ty>
    struct result_of {
    typedef T0 type;
    };

[Added with TR1]

The template class defines its member type as a synonym for the return type of a function call described by its template argument Ty. The template argument must be of the form Fty(T1, T2, ..., TN), where Fty is a callable type. The template determines the return type according to the first of the following rules that applies:

unary_function

template<class Arg, class Result>
    struct unary_function {
    typedef Arg argument_type;
    typedef Result result_type;
    };

The template class serves as a base for classes that define a member function of the form:

result_type operator()(const argument_type&) const

or a similar form taking one argument.

Hence, all such unary functions can refer to their sole argument type as argument_type and their return type as result_type.

unary_negate

template<class Fn1>
    class unary_negate
        : public unary_function<
            typename Fn1::argument_type,
            bool> {
public:
    explicit unary_negate(const Fn1& Func);
    bool operator()(
        const typename Fn1::argument_type& left) const;
    };

The template class stores a copy of func, which must be a unary function object. It defines its member function operator() as returning !func(left).

Functions

bind
bind1st
bind2nd
cref
mem_fn
mem_fun
mem_fun_ref
not1
not2
ptr_fun
ref
swap

bind

template <class Fty, class T1, class T2, ..., class TN>
   unspecified bind(Fty fn, T1 t1, T2 t2, ..., TN tN);
template <class Ret, class Fty, class T1, class T2, ..., class TN>
   unspecified bind(Fty fn, T1 t1, T2 t2, ..., TN tN);

[Added with TR1]

The types Fty, T1, T2, ..., TN must be copy constructible, and INVOKE(fn, t1, ..., tN) must be a valid expression for some values w1, w2, ..., wN.

The first template function returns a forwarding call wrapper g with a weak result type. The effect of g(u1, u2, ..., uM) is INVOKE(f, v1, v2, ..., vN, result_of<Fty cv (V1, V2, ..., VN)>::type), where cv is the cv-qualifiers of g and the values and types of the bound arguments v1, v2, ..., vN are determined as specified below.

The second template function returns a forwarding call wrapper g with a nested type result_type that is a synonym for Ret. The effect of g(u1, u2, ..., uM) is INVOKE(f, v1, v2, ..., vN, Ret), where cv is the cv-qualifiers of g and the values and types of the bound arguments v1, v2, ..., vN are determined as specified below.

The values of the bound arguments v1, v2, ..., vN and their corresponding types V1, V2, ..., VN depend on the type of the corresponding argument ti of type Ti in the call to bind and the cv-qualifiers cv of the call wrapper g as follows:

For example, given a function f(int, int) the expression bind(f, _1, 0) returns a forwarding call wrapper cw such that cw(x) calls f(x, 0). The expression bind(f, 0, _1) returns a forwarding call wrapper cw such that cw(x) calls f(0, x).

The number of arguments in a call to bind in addition to the argument fn must be equal to the number of arguments that can be passed to the callable object fn. Thus, bind(cos, 1.0) is correct, and both bind(cos) and bind(cos, _1, 0.0) are incorrect.

The number of arguments in the function call to the call wrapper returned by bind must be at least as large as the highest numbered value of is_placeholder<PH>::value for all of the placeholder arguments in the call to bind. Thus, bind(cos, _2)(0.0, 1.0) is correct (and returns cos(1.0)), and bind(cos, _2)(0.0) is incorrect.

bind1st

template<class Fn2, class Ty>
    binder1st<Fn2> bind1st(const Fn2& func, const Ty& left);

The function returns binder1st<Fn2>(func, typename Fn2::first_argument_type(left)).

bind2nd

template<class Fn2, class Ty>
    binder2nd<Fn2> bind2nd(const Fn2& func, const Ty& right);

The function returns binder2nd<Fn2>(func, typename Fn2::second_argument_type(right)).

cref

template <class Ty>
    reference_wrapper<const Ty> cref(const Ty& arg);
template <class Ty>
    reference_wrapper<const Ty> cref(const reference_wrapper<Ty>& arg);

[Added with TR1]

The first function returns reference_wrapper<const Ty>(arg.get()). The second function returns reference_wrapper<const Ty>(arg).

mem_fn

template <class Ret, class Ty>
    unspecified mem_fn(Ret Ty::*pm);

[Added with TR1]

The template function returns a simple call wrapper cw, with a weak result type, such that the expression cw(t, a2, ..., aN) is equivalent to INVOKE (pm, t, a2, ..., aN). It does not throw any exceptions.

The returned call wrapper is derived from std::unary_function<cv Ty*, Ret> (hence defining the nested type result_type as a synonym for Ret and the nested type argument_type as a synonym for cv Ty*) only if the type Ty is a pointer to member function with cv-qualifier cv that takes no arguments.

The returned call wrapper is derived from std::binary_function<cv Ty*, T2, Ret> (hence defining the nested type result_type as a synonym for Ret, the nested type first argument_type as a synonym for cv Ty*, and the nested type second argument_type as a synonym for T2) only if the type Ty is a pointer to member function with cv-qualifier cv that takes one argument, of type T2.

mem_fun

template<class Result, class Ty>
    mem_fun_t<Result, Ty> mem_fun(Result (Ty::*pm)());
template<class Result, class Ty, class Arg>
    mem_fun1_t<Result, Ty, Arg> mem_fun(Result (Ty::*pm)(Arg));
template<class Result, class Ty>
    const_mem_fun_t<Result, Ty> mem_fun(Result (Ty::*pm)() const);
template<class Result, class Ty, class Arg>
    const_mem_fun1_t<Result, Ty, Arg> mem_fun(Result (Ty::*pm)(Arg) const);

The template function returns pm cast to the return type.

mem_fun_ref

template<class Result, class Ty>
    mem_fun_ref_t<Result, Ty> mem_fun_ref(Result (Ty::*pm)());
template<class Result, class Ty, class Arg>
    mem_fun1_ref_t<Result, Ty, Arg> mem_fun_ref(Result (Ty::*pm)(Arg));
template<class Result, class Ty>
    const_mem_fun_ref_t<Result, Ty> mem_fun_ref(Result (Ty::*pm)() const);
template<class Result, class Ty, class Arg>
    const_mem_fun1_ref_t<Result, Ty, Arg> mem_fun_ref(Result (Ty::*pm)(Arg) const);

The template function returns pm cast to the return type.

not1

template<class Fn1>
    unary_negate<Fn1> not1(const Fn1& func);

The template function returns unary_negate<Fn1>(func).

not2

template<class Fn2>
    binary_negate<Fn2> not2(const Fn2& func);

The template function returns binary_negate<Fn2>(func).

ptr_fun

template<class Arg, class Result>
    pointer_to_unary_function<Arg, Result>
        ptr_fun(Result (*pfunc)(Arg));
template<class Arg1, class Arg2, class Result>
    pointer_to_binary_function<Arg1, Arg2, Result>
        ptr_fun(Result (*pfunc)(Arg1, Arg2));

The first template function returns pointer_to_unary_function<Arg, Result>(pfunc).

The second template function returns pointer_to_binary_function<Arg1, Arg2, Result>(pfunc).

ref

template<class Ty>
    reference_wrapper<Ty> ref(Ty& arg);
template<class Ty>
    reference_wrapper<Ty> ref(reference_wrapper<Ty>& arg);

[Added with TR1]

The first function returns reference_wrapper<Ty>(arg.get()). The second function returns reference_wrapper<Ty>(arg).

swap

template <class Fty>
void swap(function<Fty>& f1,
    function<Fty>& f2);

[Added with TR1]

The function returns f1.swap(f2).

Operators

operator!=
operator==

operator!=

template<class Fty>
    bool operator!=(const function<Fty>& f, null_ptr_type npc);
template<class Fty>
    bool operator!=(null_ptr_type npc, const function<Fty>& f);

[Added with TR1]

The operators both take an argument that is a reference to a function object and an argument that is a null pointer. Both return true only if the function object is not empty.

operator==

template<class Fty>
    bool operator==(const function<Fty>& f, null_ptr_type npc);
template<class Fty>
    bool operator==(null_ptr_type npc, const function<Fty>& f);

[Added with TR1]

The operators both take an argument that is a reference to a function object and an argument that is a null pointer. Both return true only if the function object is empty.

Structures

is_bind_expression
is_placeholder

is_bind_expression

template <class Ty>
    struct is_bind_expression {
    static const bool value;
    };

[Added with TR1]

The constant value value is true if the type Ty is a type returned by a call to bind, otherwise false.

is_placeholder

template <class Ty>
    struct is_placeholder {
    static const int value;
    };

[Added with TR1]

The constant value value is 0 if the type Ty is not a placeholder; otherwise, its value is the position of the function call argument that it binds to.

Objects

_1

namespace placeholders {
  extern unspecified _1;  // _2, _3, ... _M
  } // namespace placeholders (within std::tr1)

[Added with TR1]

The objects _1, _2, ... _M are placeholders designating the first, second, ..., Mth argument, respectively in a function call to an object returned by bind. In this implementation the value of M is 10.

Copyright note

Certain materials included or referred to in this document are copyright P.J. Plauger and/or Dinkumware, Ltd. or are based on materials that are copyright P.J. Plauger and/or Dinkumware, Ltd.

Certain materials included or referred to in this document are copyright Hewlett-Packard Company or are based on materials that are copyright Hewlett-Packard Company.

Notwithstanding the meta-data for this document, copyright information for this document is as follows:

Copyright © IBM Corp. 1999, 2010. & Copyright © P.J. Plauger and/or Dinkumware, Ltd. 1992-2006. & Copyright © 1994 Hewlett-Packard Company.