I created a function which, given a list of some type T, and a predicate (a pointer to a specified function), counts how many elements in the list return true.
This works with atomic predicates (isEven,isOdd,is_less_than_42), but what should I do if I want to use it with N-ary predicates? Is there any way to pass an optional list of N-1 arguments needed by the N-ary predicate?
template<typename T, class Pred>
int evaluate(listofelements<T> &sm, Pred pred){
typename listofelements<T>:: iterator begin, end;
int count=0;
begin=sm.begin();
end=sm.end();
while(begin!=end){
if(pred(*(begin->data))) count++;
begin++;
}
return count;
}