/*
CS371p: Quiz #16 (5 pts)
*/
/* -----------------------------------------------------------------------
1. Define the function count_if().
(4 pts)
*/
#include <cassert> // assert
#include <cctype> // isupper
#include <cstring> // strlen
template <typename II, typename UP>
int count_if (II b, II e, UP f) {
int c = 0;
while (b != e) {
if (f(*b))
++c;
++b;}
return c;}
int main () {
using namespace std;
assert(!isupper('a'));
assert( isupper('A'));
typedef int (*CUP) (int);
const char a[] = "abCbA";
const int s = strlen(a);
const CUP p = isupper;
assert(count_if(a, a + s, isupper) == 2);
assert(count_if(a, a + s, p) == 2);
return 0;}
syntax highlighted by Code2HTML, v. 0.9.1