ADC Home > Reference Library > Reference > Darwin > Miscellaneous User Space API Reference

 


stl_function.h

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

operator _Identity


template <class _Tp> struct _Identity : public unary_function<_Tp,_Tp> { 
    _Tp& operator()(
        _Tp& __x) const ;
Discussion

@}


operator equal_to


// 20.3.3 comparisons 
/** @defgroup s20_3_3_comparisons Comparison Classes
The library provides six wrapper functors for all the basic comparisons
in C++, like @c <.

@{
    */
/// One of the @link s20_3_3_comparisons comparison functors@endlink. 
template <class _Tp> struct equal_to : public binary_function<_Tp, _Tp, bool> { 
    bool operator()(
        const _Tp& __x,
        const _Tp& __y) const ;
Discussion

@}


operator logical_and


// 20.3.4 logical operations 
/** @defgroup s20_3_4_logical Boolean Operations Classes
Here are wrapper functors for Boolean operations: @c &&, @c ||, and @c !.

@{
    */
/// One of the @link s20_3_4_logical Boolean operations functors@endlink. 
template <class _Tp> struct logical_and : public binary_function<_Tp, _Tp, bool> { 
    bool operator()(
        const _Tp& __x,
        const _Tp& __y) const ;
Discussion

@}


operator plus


// 20.3.2 arithmetic 
/** @defgroup s20_3_2_arithmetic Arithmetic Classes
Because basic math often needs to be done during an algorithm, the library
provides functors for those operations. See the documentation for
@link s20_3_1_base the base classes@endlink for examples of their use.

@{
    */
/// One of the @link s20_3_2_arithmetic math functors@endlink. 
template <class _Tp> struct plus : public binary_function<_Tp, _Tp, _Tp> { 
    _Tp operator()(
        const _Tp& __x,
        const _Tp& __y) const ;
Discussion

@}

Typedefs


binary_function


template <class _Arg1, class _Arg2, class _Result> struct binary_function { 
    typedef _Arg1 first_argument_type; ///< the type of the first argument 
    /// (no surprises here)  
    typedef _Arg2 second_argument_type; ///< the type of the second argument 
    typedef _Result result_type; ///< type of the return type 
};  
Discussion

This is one of the functor base classes@endlink.


unary_function


/**
This is one of the @link s20_3_1_base functor base classes@endlink.
    */
template <class _Arg, class _Result> struct unary_function { 
    typedef _Arg argument_type; ///< @c argument_type is the type of the 
    /// argument (no surprises here)  
    typedef _Result result_type; ///< @c result_type is the return 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.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.
Last Updated: 2006-06-20