|
ALINK="#ff0000">
pointer_to_binary_function<Arg1, Arg2, Result>
DescriptionPointer_to_binary_function is a function object adaptor that allows a function pointer Result (*f)(Arg1, Arg2) to be treated as an Adaptable Binary Function. That is: if F is a pointer_to_binary_function<Arg1, Arg2, Result> that was initialized with an underlying function pointer f of type Result (*)(Arg1, Arg2), then F(x, y) calls the function f(x, y). The difference between f and F is that pointer_to_binary_function is an Adaptable Binary Function, i.e. it defines the nested typedefs first_argument_type, second_argument_type, and result_type.Note that a function pointer of type Result (*)(Arg1, Arg2) is a perfectly good Binary Function object, and may be passed to an STL algorithm that expects an argument that is a Binary Function. The only reason for using the pointer_to_binary_function class is if you need to use an ordinary function in a context that requires an Adaptable Binary Function, e.g. as the argument of a function object adaptor. Most of the time, you need not declare an object of type pointer_to_binary_function directly. It is almost always easier to construct one using the ptr_fun function. ExampleThe following code fragment finds the first string in a list that is equal to "OK". It uses the standard library function strcmp as an argument to a function object adaptor, so it must first use a pointer_to_binary_function adaptor to give strcmp the Adaptable Binary Function interface.list<char*> L; ... list<char*>::iterator item = find_if(L.begin(), L.end(), not1(binder2nd(ptr_fun(strcmp), "OK"))); DefinitionDefined in the standard header functional, and in the nonstandard backward-compatibility header function.h.Template parameters
Model ofAdaptable Binary FunctionType requirements
Public base classesbinary_function<Arg1, Arg2, Result>Members
New membersThese members are not defined in the Adaptable Binary Function requirements, but are specific to pointer_to_binary_function.
NotesSee alsopointer_to_unary_function, ptr_fun, Adaptable Binary FunctionCopyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|