<functional>


binary_function · binary_negate · binder1st · binder2nd · bit_and · bit_or · bit_xor · 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 · hash · is_bind_expression · is_placeholder · mem_fn · operator!== · operator== · ref · reference_wrapper · swap · uses_allocator · _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 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.


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 bit_and; [added with C++11]
template<class Ty>
    struct bit_or; [added with C++11]
template<class Ty>
    struct bit_xor; [added with C++11]

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

        // TEMPLATE STRUCT hash
template<class Ty> [added with C++11]
    struct hash;
template<>
    struct hash<bool>;
template<>
    struct hash<char>;
template<>
    struct hash<signed char>;
template<>
    struct hash<unsigned char>;
template<>
    struct hash<char16_t>;
template<>
    struct hash<char32_t>;
template<>
    struct hash<wchar_t>;
template<>
    struct hash<short>;
template<>
    struct hash<unsigned short>;
template<>
    struct hash<int>;
template<>
    struct hash<unsigned int>;
template<>
    struct hash<long>;
template<>
    struct hash<unsigned long>;
template<>
    struct hash<long long>;
template<>
    struct hash<unsigned long long>;
template<>
    struct hash<float>;
template<>
    struct hash<double>;
template<>
    struct hash<long double>;
template<Ty>
    struct hash<Ty *>;

        // REFERENCE WRAPPERS
template<class Ty> [added with C++11]
    reference_wrapper<Ty>
        ref(Ty&) noexcept;
template<class Ty> [added with C++11]
    reference_wrapper<Ty>
        ref(reference_wrapper<Ty>&) noexcept;
template<class Ty> [added with C++11]
    reference_wrapper<const Ty>
        cref(const Ty&) noexcept;
template<class Ty> [added with C++11]
    reference_wrapper<const Ty>
        cref(const reference_wrapper<Ty>&) noexcept;
template<class Ty> [added with C++11]
    struct reference_wrapper;

        // ENHANCED MEMBER POINTER ADAPTER
template<class Ret, class Arg0>
    unspecified mem_fn(
    Ret Arg0::*const pm); [added with C++11]

template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...)); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) volatile); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const volatile); [added with C++11]

template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) &); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const &); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) volatile &); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const volatile &); [added with C++11]

template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) &&); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const &&); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) volatile &&); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const volatile &&); [added with C++11]

        // FUNCTION OBJECT WRAPPERS
class bad_function_call; [added with C++11]
template<class Fty> [added with C++11]
    class function;
template<class Ret, class... Types, class Alloc>
    struct uses_allocator<function<Ret (Types...)>, Alloc>; [added with C++11]

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

template<class Fty>
    bool operator!=(const function<Fty>&,
        nullptr_t) noexcept;
template<class Fty>
    bool operator!=(nullptr_t,
        const function<Fty>&) noexcept;
template<class Fty>
    bool operator==(const function<Fty>&,
        nullptr_t) noexcept;
template<class Fty>
    bool operator==(nullptr_t,
        const function<Fty>& noexcept);

        // ENHANCED BINDERS
template<class Fty, class ... Bargs>
    unspecified bind(Fty&&, Bargs&&... bargs);
template<class Ret, class Fty, class ... Bargs>
    unspecified bind(Fty&&, Bargs&&... bargs);

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 {
using std::bad_function_call; using std::bind; [added with C++11]
using std::cref; using std::function;
using std::hash; using std::is_bind_expression;
using std::is_placeholder; using std::mem_fn;
using std::ref; using std::reference_wrapper;
using std::swap;
        namespace placeholders {
using std::placeholders;
        } // namespace placeholders
    } // namespace tr1
}  // namespace std

bad_function_call

class bad_function_call [added with C++11]
    : public exception {
    bad_function_call() noexcept;
    };

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.

Beginning with C++11, any use of binary_function as a base class should be taken only as a shorthand for the definition of the types described above. The base class is not necessarily present.

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 ... T>
    unspecified bind(Fty&&, T&&... t);
template<class Ret, class Fty, class ... T>
    unspecified bind(Fty&&, T&&... t);

The types Fty, T... must be copy or move constructible, and INVOKE(fn, t...) must be a valid expression for some values w....

The first template function returns a forwarding call wrapper g with a weak result type. The effect of g(u...) is INVOKE(f, forward<V>(v)..., result_of<Fty cv (V...)>::type), where cv is the cv-qualifiers of g and the values and types of the bound arguments v... 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(u...) is INVOKE(f, v..., Ret), where cv is the cv-qualifiers of g and the values and types of the bound arguments v... are determined as specified below.

The values of the bound arguments v... and their corresponding types V... depend on the type of the corresponding arguments t... of types T... in the call to bind and the cv-qualifiers cv of the call wrapper g as follows:

Beginning with C++11, the traditional limit of ten arguments to a call to bind is removed.

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

bit_and

template<class Ty>
    struct bit_and
        : 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.

bit_or

template<class Ty>
    struct bit_or
        : 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.

bit_xor

template<class Ty>
    struct bit_xor
        : 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.

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 C++11]
    reference_wrapper<const Ty>
       cref(const Ty& arg) noexcept;
template<class Ty> [added with C++11]
    reference_wrapper<const Ty>
        cref(const reference_wrapper<Ty>& arg) noexcept;

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 C++11]
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() noexcept;
    function(nullptr_t) noexcept; [added with C++11]
    template<class Alloc>
        function(allocator_arg_t, const Alloc& al) noexcept; [added with C++11]
    template<class Alloc>
        function(allocator_arg_t, const Alloc& al,
            nullptr_t) noexcept; [added with C++11]

    function(const function& right);
    template<class Alloc>
        function(allocator_arg_t, const Alloc& al,
            const function& right); [added with C++11]
    function(function&& right); [added with C++11]
    template<class Alloc>
        function(allocator_arg_t, const Alloc& al,
            function&& right); [added with C++11]

    template<class Fty2>
        function(Fty2 func);
    template<class Fty2>
        function(reference_wrapper<Fty2> func);
    template<class Fty2, class Alloc>
        function(Fty2 func, const Alloc& al); [added with C++11]
    template<class Fty2, class Alloc>
        function(allocator_arg_t, const Alloc& al,
            Fty2 func); [added with C++11]
    template<class Fty2, class Alloc>
        function(reference_wrapper<Fty2> func, const Alloc& al); [added with C++11]

    function& operator=(const function& func);
    function& operator=(nullptr_t); [added with C++11]
    function& operator=(function&& func); [added with C++11]
    template<class Fty2>
        function& operator=(reference_wrapper<Fty2> func) noexcept;
    template<class Fty2>
        function& operator=(Fty2&& func); [added with C++11]

    template<class Fty2, class Alloc>
        void assign(Fty2&& func, const Alloc& al); [added with C++11]

    void swap(function& right) noexcept;

    explicit operator bool() const noexcept;
    result_type operator()(T1, T2, ....., TN) const;

    const type_info& target_type() const noexcept;
    template<class Fty2>
        Fty2 *target() noexcept;
    template<class Fty2>
        const Fty2 *target() const noexcept;
    };

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 arguments 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::assign

template<class Fty2, class Alloc>
    void assign(Fty2&& func, const Alloc& al); [added with C++11]

The member function replaces the callable object held by *this with the moved callable object passed as the operand. It allocates storage with the allocator object al.

function::function

function() noexcept;
function(nullptr_t) noexcept; [added with C++11]
template<class Alloc>
    function(allocator_arg_t, const Alloc& al) noexcept; [added with C++11]
template<class Alloc>
    function(allocator_arg_t, const Alloc& al,
        nullptr_t) noexcept; [added with C++11]

function(const function& right);
template<class Alloc>
    function(allocator_arg_t, const Alloc& al,
        const function& right); [added with C++11]
function(function&& right); [added with C++11]
template<class Alloc>
    function(allocator_arg_t, const Alloc& al,
        function&& right); [added with C++11]

template<class Fty2>
    function(Fty2 func);
template<class Fty2>
    function(reference_wrapper<Fty2> func);
template<class Fty2, class Alloc>
    function(Fty2 func, const Alloc& al); [added with C++11]
template<class Fty2, class Alloc>
    function(allocator_arg_t, const Alloc& al,
        Fty2 func); [added with C++11]
template<class Fty2, class Alloc>
    function(reference_wrapper<Fty2> func, const Alloc& al); [added with C++11]

The first four constructors construct an empty function object. The remaining constructors construct a function object that holds the callable object passed as the operand. If the constructor has an argument al, it is used to allocate storage for the stored object.

function::operator=

function& operator=(const function& func);
function& operator=(nullptr_t); [added with C++11]
function& operator=(function&& func); [added with C++11]
template<class Fty2>
    function& operator=(reference_wrapper<Fty2> func) noexcept;
template<class Fty2>
    function& operator=(Fty2&& func); [added with C++11]

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

function::operator bool

explicit operator bool() noexcept;

The operator returns a value that is convertible to bool with a true value only if the object is not 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) noexcept;

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

function::target

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

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.

function::target_type

const type_info& target_type() const noexcept;

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

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

hash

template<class Ty>
    struct hash [added with C++11]
        : public unary_function<Ty, size_t> {
    size_t operator()(Ty val) const;
    };
template<>
    struct hash<bool>;
template<>
    struct hash<char>;
template<>
    struct hash<signed char>;
template<>
    struct hash<unsigned char>;
template<>
    struct hash<char16_t>;
template<>
    struct hash<char32_t>;
template<>
    struct hash<wchar_t>;
template<>
    struct hash<short>;
template<>
    struct hash<unsigned short>;
template<>
    struct hash<int>;
template<>
    struct hash<unsigned int>;
template<>
    struct hash<long>;
template<>
    struct hash<unsigned long>;
template<>
    struct hash<long long>;
template<>
    struct hash<unsigned long long>;
template<>
    struct hash<float>;
template<>
    struct hash<double>;
template<>
    struct hash<long double>;
template<Ty>
    struct hash<Ty *>;

The template class defines its member function as returning a value uniquely determined by val. Its member function defines a hash function, suitable for mapping values of type Ty to a distribution of index values. The library provides specializations for the scalar types show here, and several other types defined in other headers in the library.

is_bind_expression

template<class Ty>
    struct is_bind_expression { [added with C++11]
    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. Specifically, is_bind_expression publicly derives from integral_constant(bool, value).

is_placeholder

template<class Ty>
    struct is_placeholder { [added with C++11]
    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. Specifically, is_placeholder publicly derives from integral_constant(int, value).

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 Arg0>
    unspecified mem_fn(
    Ret Arg0::*const pm); [added with C++11]

template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...)); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) volatile); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const volatile); [added with C++11]

template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) &); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const &); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) volatile &); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const volatile &); [added with C++11]

template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) &&); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const &&); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) volatile &&); [added with C++11]
template<class Ret, class Arg0, class... Types>
    unspecified mem_fn(
    Ret (Arg0::*pm)(Types...) const volatile &); [added with C++11]

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 defines the nested type result_type as a synonym for Ret and the nested type argument_type as a synonym for cv Arg0 *) only if the type Arg0 * is a pointer to member function.

The returned call wrapper defines the nested type result_type as a synonym for Ret, the nested type first argument_type as a synonym for cv Arg0 *, and the nested type second argument_type as a synonym for T2) only if the type Arg0 * is a pointer to member function with cv-qualifier cv that takes one argument, of type T2.

The function throws nothing.

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 C++11]
    bool operator!=(const function<Fty>& f, nullptr_t npc) noexcept;
template<class Fty>
    bool operator!=(nullptr_t npc, const function<Fty>& f) noexcept;

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 C++11]
    bool operator==(const function<Fty>& f, nullptr_t npc) noexcept;
template<class Fty>
    bool operator==(nullptr_t npc, const function<Fty>& f) noexcept;

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

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

reference_wrapper

template<class Ty> [added with C++11]
    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

    reference_wrapper(Ty&) noexcept;
    reference_wrapper(const reference_wrapper&) noexcept;
    reference_wrapper(Ty&&) = delete; [added with C++11]

    const reference_wrapper&
        operator=(const reference_wrapper&) noexcept;

    Ty& get() const noexcept;
    operator Ty&() const noexcept;
    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 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:

reference_wrapper::get

Ty& get() const noexcept;

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

reference_wrapper::operator

const reference_wrapper&
    operator=(const reference_wrapper& right) noexcept;

The member operator copy assigns right.

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) noexcept;

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

reference_wrapper::operator Ty&

operator Ty&() const noexcept;

The member operator returns *ptr.

reference_wrapper::reference_wrapper

reference_wrapper(Ty& val) noexcept;
reference_wrapper(const reference_wrapper&) noexcept;
reference_wrapper(Ty&&) = delete; [added with C++11]

The first constructor sets the stored value ptr to &val.

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.

swap

template<class Fty> [added with C++11]
    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.

Beginning with C++11, any use of unary_function as a base class should be taken only as a shorthand for the definition of the types described above. The base class is not necessarily present.

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

uses_allocator

template<class Ret, class... Types, class Alloc>
    struct uses_allocator<function<Ret (Types...)>, Alloc>; [added with C++11]

The specializations always hold true.

_1

namespace placeholders { [added with C++11]
  extern unspecified _1;  // _2, _3, ... _M
  } // namespace placeholders (within std)

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-2013 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.