DINKUMWARE Ltd -- Leaders in Standard Library implementation. DINKUMWARE Ltd - www.dinkumware.com, Concord MA USA
Home Dinkum Compleat Reference Dinkum Reports Dinkum C++ tr1 Dinkum C++ Dinkum C99 Dinkum Supplemental Dinkum Exam
 
 
 
 
 
 
loading... Searching...
 
<functional>

<functional>


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 · greater · greater_equal · 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 · unary_function · unary_negate

bind1st · bind2nd · mem_fun · mem_fun_ref · not1 · not2 · ptr_fun

bad_function_call · bind · cref · function · is_bind_expression · is_placeholder · mem_fn · operator!== · operator== · ref · reference_wrapper · result_of · swap · _1


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.

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 forrwards 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:

  • (t1.*f)(t2, ..., tN) when f is a pointer to member function of class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T;
  • ((*t1).*f)(t2, ..., tN) when f is a pointer to member function of class T and t1 is not one of the types described in the previous item;
  • t1.*f when f is a pointer to member data of class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T;
  • (*t1).*f when f is a pointer to member data of class class T and t1 is not one of the types described in the previous item;
  • f(t1, t2, ..., tN) in all other cases.

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:

  • if T is a pointer to function, result_type is a synonym for the return type of T;
  • if T is a pointer to member function, result_type is a synonym for the return type of T;
  • if T is a pointer to data member, result_type is a synonym for the declared type of the data member;
  • if T is a class type with a member type result_type, then result_type is a synonym for T::result_type;
  • otherwise there is no member result_type.

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.


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& right);
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);

    namespace tr1 {  [added with TR1]
        // 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

bad_function_call

class bad_function_call  [added with TR1]
    : public std::exception {
    };

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).

bind

template <class Fty, class T1, class T2, ..., class TN>  [added with TR1]
   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);

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:

  • if ti is of type reference_wrapper<T> the argument vi is ti.get() and its type Vi is T&;
  • if the value of std::tr1::is_bind_expression<Ti>::value is true the argument vi is ti(u1, u2, ..., uM) and its type Vi is result_of<Ti cv (U1&, U2&, ..., UN&>::type;
  • if the value j of std::tr1::is_placeholder<Ti>::value is not zero the argument vi is uj and its type Vi is Uj&;
  • otherwise the argument vi is ti and its type Vi is Ti cv &.

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)).

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<const 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.

cref

template <class Ty>  [added with TR1]
    reference_wrapper<const Ty> cref(const Ty& arg);
template <class Ty>
    reference_wrapper<const Ty> cref(const reference_wrapper<Ty>& arg);

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

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

template <class Fty>  [added with TR1]
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;
    template<class Fty2>
      bool operator!=(const Fty2&) const;
    };

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:

  • 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 constant; 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.

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.

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 value equal to !empty().

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::result_type

typedef Ret result_type;

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

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.

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.

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 if Ty is an object pointer type. (It will compare two pointer values consistently even if they don't point into the same array.)

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. (It will compare two pointer values consistently even if they don't point into the same array.)

is_bind_expression

template <class Ty>
    struct is_bind_expression {  [added with TR1]
    static const bool value;
    };

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 {  [added with TR1]
    static const int value;
    };

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.

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. (It will compare two pointer values consistently even if they don't point into the same array.)

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 if Ty is an object pointer type. (It will compare two pointer values consistently even if they don't point into the same array.)

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_fn

template <class Ret, class Ty>  [added with TR1]
    unspecified mem_fn(Ret Ty::*pm);

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.

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.

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).

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.

operator!=

template<class Fty>  [added with TR1]
    bool operator!=(const function<Fty>& f, null_ptr_type npc);
template<class Fty>
    bool operator!=(null_ptr_type npc, const function<Fty>& f);

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

operator==

template<class Fty>  [added with TR1]
    bool operator==(const function<Fty>& f, null_ptr_type npc);
template<class Fty>
    bool operator==(null_ptr_type npc, const function<Fty>& f);

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

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).

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>  [added with TR1]
    reference_wrapper<Ty> ref(Ty& arg);
template<class Ty>
    reference_wrapper<Ty> ref(reference_wrapper<Ty>& arg);

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

reference_wrapper

template<class Ty>  [added with TR1]
    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
    };

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 function type or pointer to function type taking one argument of type T1 and returning Ret; or
  • a pointer to a member function Ret T::f() cv, where cv represents the member function's cv-qualifiers; the type T1 is cv T*; or
  • a class type that is derived from unary_function<T1, Ret>.
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:
  • a function type or pointer to function type taking two arguments of types T1 and T2 and returning Ret; or
  • a pointer to a member function Ret T::f(T2) cv, where cv represents the member function's cv-qualifiers; the type T1 is cv T*; or
  • a class type that is derived from binary_function<T1, T2, Ret>.

reference_wrapper::get

Ty& get() const;

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

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.

reference_wrapper::reference_wrapper

explicit reference_wrapper(Ty& val);

The constructor sets the stored value ptr to &val.

reference_wrapper::result_type

typedef T0 result_type;

The template has a weak result type.

reference_wrapper::type

typedef Ty type;

The typedef is a synonym for the template argument Ty.

result_of

template<class Ty>  [added with TR1]
    struct result_of {
    typedef T0 type;
    };

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:

  • if Fty is a pointer to function type R(*)(U1, U2, ..., UN) the return type is R;
  • if Fty is a pointer to member function type R(U1::*)(U2, ..., UN) the return type is R;
  • if Fty is a pointer to data member type R U1::* the return type is R;
  • if Fty is a class with a member typedef result_type the return type is Fty::result_type;
  • if N is 0 (that is, Ty is of the form Fty()) the return type is void;
  • If Fty is a class with a member template named result the return type is Fty::result<T1, T2, ..., TN>::type;
  • in all other cases it is an error.

swap

template <class Fty>  [added with TR1]
void swap(function<Fty>& f1,
    function<Fty>& f2);

The function returns f1.swap(f2).

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).

_1

namespace placeholders {  [added with TR1]
  extern unspecified _1;  // _2, _3, ... _M
  } // namespace placeholders (within std::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.


See also the Table of Contents and the Index.

Copyright © 1992-2006 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.