# <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`**
* * *
Include the [STL](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#STL)
standard header **``**
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.
namespace std {
template
struct unary_function;
template
struct binary_function;
template
struct plus;
template
struct minus;
template
struct multiplies;
template
struct divides;
template
struct modulus;
template
struct negate;
template
struct equal_to;
template
struct not_equal_to;
template
struct greater;
template
struct less;
template
struct greater_equal;
template
struct less_equal;
template
struct logical_and;
template
struct logical_or;
template
struct logical_not;
template
struct unary_negate;
template
struct binary_negate;
template
class binder1st;
template
class binder2nd;
template
class pointer_to_unary_function;
template
class pointer_to_binary_function;
template
struct mem_fun_t;
template
struct mem_fun1_t;
template
struct const_mem_fun_t;
template
struct const_mem_fun1_t;
template
struct mem_fun_ref_t;
template
struct mem_fun1_ref_t;
template
struct const_mem_fun_ref_t;
template
struct const_mem_fun1_ref_t;
// TEMPLATE FUNCTIONS
template
unary_negate not1(const Fn1& func);
template
binary_negate not2(const Fn2& func);
template
binder1st bind1st(const Fn2& func, const Ty& left);
template
binder2nd bind2nd(const Fn2& func, const Ty& right);
template
pointer_to_unary_function
ptr_fun(Result (*)(Arg));
template
pointer_to_binary_function
ptr_fun(Result (*)(Arg1, Arg2));
template
mem_fun_t mem_fun(Result (Ty::*pm)());
template
mem_fun1_t mem_fun(Result (Ty::*pm)(Arg left));
template
const_mem_fun_t mem_fun(Result (Ty::*pm)() const);
template
const_mem_fun1_t mem_fun(Result (Ty::*pm)(Arg left) const);
template
mem_fun_ref_t mem_fun_ref(Result (Ty::*pm)());
template
mem_fun1_ref_t
mem_fun_ref(Result (Ty::*pm)(Arg left));
template
const_mem_fun_ref_t mem_fun_ref(Result (Ty::*pm)() const);
template
const_mem_fun1_ref_t
mem_fun_ref(Result (Ty::*pm)(Arg left) const);
} // namespace stdCopy to clipboard
## `binary_function`
template
struct binary_function {
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};Copy to clipboard
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&) constCopy to clipboard
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 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;
};Copy to clipboard
The template class stores a copy of `func`, which
must be a [binary function](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_functio2.html#binary%20functions) object.
It defines its member function **`operator()`**
as returning `!func(left, right)`.
## `bind1st`
template
binder1st bind1st(const Fn2& func, const Ty& left);Copy to clipboard
The function returns
`binder1st(func,
typename Fn2::first_argument_type(left))`.
## `bind2nd`
template
binder2nd bind2nd(const Fn2& func, const Ty& right);Copy to clipboard
The function returns
`binder2nd(func,
typename Fn2::second_argument_type(right))`.
## `binder1st`
template
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;
};Copy to clipboard
The template class stores a copy of `func`, which
must be a [binary function](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_functio2.html#binary%20functions) object, in
**`op`**,
and a copy of `left` in
**`value`**.
It defines its member function **`operator()`**
as returning `op(value, right)`.
## `binder2nd`
template
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;
};Copy to clipboard
The template class stores a copy of `func`, which
must be a [binary function](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_functio2.html#binary%20functions) 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
struct const_mem_fun_t
: public unary_function {
explicit const_mem_fun_t(Result (Ty::*pm)() const);
Result operator()(const Ty *pleft) const;
};Copy to clipboard
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
struct const_mem_fun_ref_t
: public unary_function {
explicit const_mem_fun_t(Result (Ty::*pm)() const);
Result operator()(const Ty& left) const;
};Copy to clipboard
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
struct const_mem_fun1_t
: public binary_function {
explicit const_mem_fun1_t(Result (Ty::*pm)(Arg) const);
Result operator()(const Ty *pleft, Arg right) const;
};Copy to clipboard
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
struct const_mem_fun1_ref_t
: public binary_function {
explicit const_mem_fun1_ref_t(Result (Ty::*pm)(Arg) const);
Result operator()(const Ty& left, Arg right) const;
};Copy to clipboard
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
struct divides : public binary_function {
Ty operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left / right`.
## `equal_to`
template
struct equal_to
: public binary_function {
bool operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left == right`.
## `greater`
template
struct greater : public binary_function {
bool operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left > right`. The member function defines a
[total ordering](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_utility.html#total%20ordering)
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
struct greater_equal
: public binary_function {
bool operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left >= right`. The member function defines a
[total ordering](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_utility.html#total%20ordering)
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`
template
struct less : public binary_function {
bool operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left < right`. The member function defines a
[total ordering](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_utility.html#total%20ordering)
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
struct less_equal
: public binary_function {
bool operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left <= right`. The member function defines a
[total ordering](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_utility.html#total%20ordering)
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
struct logical_and
: public binary_function {
bool operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left && right`.
## `logical_not`
template
struct logical_not : public unary_function {
bool operator()(const Ty& left) const;
};Copy to clipboard
The template class defines its member function as returning
`!left`.
## `logical_or`
template
struct logical_or
: public binary_function {
bool operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left || right`.
## `mem_fun`
template
mem_fun_t mem_fun(Result (Ty::*pm)());
template
mem_fun1_t mem_fun(Result (Ty::*pm)(Arg));
template
const_mem_fun_t
mem_fun(Result (Ty::*pm)() const);
template
const_mem_fun1_t
mem_fun(Result (Ty::*pm)(Arg) const);Copy to clipboard
The template function returns `pm` cast to the return type.
## `mem_fun_ref`
template
mem_fun_ref_t mem_fun_ref(Result (Ty::*pm)());
template
mem_fun1_ref_t mem_fun_ref(Result (Ty::*pm)(Arg));
template
const_mem_fun_ref_t mem_fun_ref(Result (Ty::*pm)() const);
template
const_mem_fun1_ref_t mem_fun_ref(Result (Ty::*pm)(Arg) const);Copy to clipboard
The template function returns `pm` cast to the return type.
## `mem_fun_t`
template
struct mem_fun_t : public unary_function {
explicit mem_fun_t(Result (Ty::*pm)());
Result operator()(Ty *pleft) const;
};Copy to clipboard
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
struct mem_fun_ref_t
: public unary_function {
explicit mem_fun_t(Result (Ty::*pm)());
Result operator()(Ty& left) const;
};Copy to clipboard
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
struct mem_fun1_t
: public binary_function {
explicit mem_fun1_t(Result (Ty::*pm)(Arg));
Result operator()(Ty *pleft, Arg right) const;
};Copy to clipboard
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
struct mem_fun1_ref_t
: public binary_function {
explicit mem_fun1_ref_t(Result (Ty::*pm)(Arg));
Result operator()(Ty& left, Arg right) const;
};Copy to clipboard
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
struct minus : public binary_function {
Ty operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left - right`.
## `modulus`
template
struct modulus : public binary_function {
Ty operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left % right`.
## `multiplies`
template
struct multiplies : public binary_function {
Ty operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left * right`.
## `negate`
template
struct negate : public unary_function {
Ty operator()(const Ty& left) const;
};Copy to clipboard
The template class defines its member function as returning
`-left`.
## `not1`
template
unary_negate not1(const Fn1& func);Copy to clipboard
The template function returns
`unary_negate(func)`.
## `not2`
template
binary_negate not2(const Fn2& func);Copy to clipboard
The template function returns
`binary_negate(func)`.
## `not_equal_to`
template
struct not_equal_to
: public binary_function {
bool operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left != right`.
## `plus`
template
struct plus : public binary_function {
Ty operator()(const Ty& left, const Ty& right) const;
};Copy to clipboard
The template class defines its member function as returning
`left + right`.
## `pointer_to_binary_function`
template
class pointer_to_binary_function
: public binary_function {
public:
explicit pointer_to_binary_function(
Result (*pfunc)(Arg1, Arg2));
Result operator()(const Arg1 left, const Arg2 right) const;
};Copy to clipboard
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 pointer_to_unary_function
: public unary_function {
public:
explicit pointer_to_unary_function(
Result (*pfunc)(Arg));
Result operator()(const Arg left) const;
};Copy to clipboard
The template class stores a copy of `pfunc`.
It defines its member function **`operator()`**
as returning `(*pfunc)(left)`.
## `ptr_fun`
template
pointer_to_unary_function
ptr_fun(Result (*pfunc)(Arg));
template
pointer_to_binary_function
ptr_fun(Result (*pfunc)(Arg1, Arg2));Copy to clipboard
The first template function returns
`pointer_to_unary_function(pfunc)`.
The second template function returns
`pointer_to_binary_function(pfunc)`.
## `unary_function`
template
struct unary_function {
typedef Arg argument_type;
typedef Result result_type;
};Copy to clipboard
The template class serves as a base for classes that define
a member function of the form:
result_type operator()(const argument_type&) constCopy to clipboard
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 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;
};Copy to clipboard
The template class stores a copy of `func`, which
must be a [unary function](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_functio2.html#unary%20functions) object.
It defines its member function **`operator()`**
as returning `!func(left)`.
* * *
See also the
**[Table of Contents](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#Table%20of%20Contents)** and the
**[Index](https://docs.qualcomm.com/doc/80-N3040-23/topic/_cpp_index.html)**.
*[Copyright](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_crit_pjp.html) © 1992-2006by P.J. Plauger. Portions derived from work[copyright](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_crit_hp.html) © 1994by Hewlett-Packard Company. All rights reserved.*
Last Published: Oct 06, 2026
Previous Topic
Next Topic