Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

bind1st, bind2nd, binder1st, binder2nd


Function Object

Summary

Templatized utilities to bind values to function objects.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <functional>
template <class Operation>
class binder1st : public unary_function<typename 
                   Operation::second_argument_type,
                   typename Operation::result_type> ;

template <class Operation, class T>
binder1st<Operation> bind1st (const Operation&, const T&);
template <class Operation>
class binder2nd : public unary_function<typename            
                   Operation::first_argument_type,
                   typename Operation::result_type> ;

template <class Operation, class T>
binder2nd<Operation> bind2nd (const Operation&, const T&);

Description

Because so many functions included in the standard library take other functions as arguments, the library includes classes that let you build new function objects out of old ones. Both bind1st() and bind2nd() are functions that take as arguments a binary function object f and a value x, and return, respectively, classes binder1st and binder2nd. The underlying function object must be a subclass of binary_function.

Class binder1st binds the value to the first argument of the binary function, and binder2nd does the same thing for the second argument of the function. The resulting classes can be used in place of a unary predicate in other function calls.

For example, you could use the count_if algorithm to count all elements in a vector that are less than or equal to 7, using the following:

This function adds one to littleNums each time the predicate is true, in other words, each time 7 is greater than the element.

Interface

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you have to write:

vector<int,allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

Function Objects



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998