pointer_to_unary_function, ptr_fun |
With this object, you can use a
regular C unary function as a unary function object. When executed, a pointer_to_unary_function
object returns the result of executing the regular C function with an operand.
Use the associated adapter function ptr_fun() to
conveniently construct a pointer_to_unary_function
object directly from a C unary function.
#include <functional>
template< class Arg, class Result >
class pointer_to_unary_function : public unary_function< Arg, Result >
) .
#include <iostream>
#include <algorithm>
#include <functional>
int array[ 3 ] = { 1, 2, 3 };
bool
even( int n_ )
{
return( n_ % 2 ) == 0;
}
void
main()
{
int* p = find_if
(
array,
array + 3,
pointer_to_unary_function< int, bool >( even )
);
if ( p != array + 3 )
cout << *p << " is even\n";
}
2 is even
#include <iostream>
#include <algorithm>
#include <functional>
int array[ 3 ] = { 1, 2, 3 };
bool
even( int n_ )
{
return( n_ % 2 ) == 0;
}
void
main()
{
int* p = find_if( array, array + 3, ptr_fun( even ) );
if ( p != array + 3 )
cout << *p << " is even\n";
}
2 is even
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.