/////// Application of functional argument /////// #include typedef int (* END_FN)(void *, int); typedef int (* BOOLEAN_FN) (void *any, int index); int or_test(void *any, BOOLEAN_FN test, END_FN is_end) { int len=0; while ( ! is_end(any,len) ) { if ( test(any, len) ) return(1); len++; } return(0); } int even(int *ip, int j) { return( (ip[j] & 01) == 0 );} int odd(int *ip, int j) { return( (ip[j] & 01) == 1 );} int int_end(int *a, int i) { return( a[i] == -1 ); } int str_end(char *a, int i) { return( a[i] == '\0' ); } int main() { int b[]={4,2,8,3,-1}; int c[]={3,7,1,10,-1}; int i = or_test(b, BOOLEAN_FN(even), END_FN(int_end)); cout << "or_test = " << i << endl; i = or_test(c, BOOLEAN_FN(odd), END_FN(int_end)); cout << "or_test = " << i << endl; return(0); }