Introduction
This is an internal header file, included by other library headers.
You should not attempt to use it directly.
Classes
- binder1st
- mem_fun_t
- pointer_to_unary_function
- unary_negate
Functions
- operator _Identity
- operator equal_to
- operator logical_and
- operator plus
template <class _Tp> struct _Identity : public unary_function<_Tp,_Tp> {
_Tp& operator()(
_Tp& __x) const ;
Discussion
@}
template <class _Tp> struct equal_to : public binary_function<_Tp, _Tp, bool> {
bool operator()(
const _Tp& __x,
const _Tp& __y) const ;
Discussion
@}
template <class _Tp> struct logical_and : public binary_function<_Tp, _Tp, bool> {
bool operator()(
const _Tp& __x,
const _Tp& __y) const ;
Discussion
@}
template <class _Tp> struct plus : public binary_function<_Tp, _Tp, _Tp> {
_Tp operator()(
const _Tp& __x,
const _Tp& __y) const ;
Discussion
@}
Typedefs
template <class _Arg1, class _Arg2, class _Result> struct binary_function {
typedef _Arg1 first_argument_type;
typedef _Arg2 second_argument_type;
typedef _Result result_type;
};
Discussion
This is one of the functor base classes@endlink.
template <class _Arg, class _Result> struct unary_function {
typedef _Arg argument_type;
typedef _Result result_type;
};
Discussion
@defgroup s20_3_1_base Functor Base Classes
Function objects, or @e functors, are objects with an @c operator()
defined and accessible. They can be passed as arguments to algorithm
templates and used in place of a function pointer. Not only is the
resulting expressiveness of the library increased, but the generated
code can be more efficient than what you might write by hand. When we
refer to "functors," then, generally we include function pointers in
the description as well.
Often, functors are only created as temporaries passed to algorithm
calls, rather than being created as named variables.
Two examples taken from the standard itself follow. To perform a
by-element addition of two vectors @c a and @c b containing @c double,
and put the result in @c a, use
\code
transform (a.begin(), a.end(), b.begin(), a.begin(), plus());
\endcode
To negate every element in @c a, use
\code
transform(a.begin(), a.end(), a.begin(), negate());
\endcode
The addition and negation functions will be inlined directly.
The standard functiors are derived from structs named @c unary_function
and @c binary_function. These two classes contain nothing but typedefs,
to aid in generic (template) programming. If you write your own
functors, you might consider doing the same.
@{
|
Did this document help you? |
Yes: Tell us what works for you.
|
|
Last Updated: 2006-06-20