pointer_to_binary_function, ptr_fun |
With this object, you can use a
regular C binary function as a binary function object. When executed, a pointer_to_binary_function
object returns the result of executing the regular C function with two operands.
Use the associated adapter function ptr_fun() to
conveniently construct a pointer_to_binary_function
object directly from a C binary function.
#include <functional>
template< class Arg1, class Arg2, class Result >
class pointer_to_binary_function : public binary_function< Arg1, Arg2, Result >
, y
) .
#include <algorithm>
#include <functional>
int input1[ 4 ] = { 7, 2, 3, 5 };
int input2[ 4 ] = { 1, 5, 5, 8 };
int
sum( int x_, int y_ )
{
return x_ + y_;
}
void
main()
{
int output[ 4 ];
transform
(
input1,
input1 + 4,
input2,
output,
pointer_to_binary_function< int, int, int >( sum )
);
for ( int i = 0; i < 4; ++i )
cout << output[ i ] << "\n";
}
8
7
8
13
#include <iostream>
#include <algorithm>
#include <functional>
int input1[ 4 ] = { 7, 2, 3, 5 };
int input2[ 4 ] = { 1, 5, 5, 8 };
int
sum( int x_, int y_ )
{
return x_ + y_;
}
void
main()
{
int output[ 4 ];
transform( input1, input1 + 4, input2, output, ptr_fun( sum ) );
for ( int i = 0; i < 4; ++i )
cout << output[ i ] << "\n";
}
8
7
8
13
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.