#include <iostream>
#include <vector>
using namespace std;

template<class InputIt, class UnaryPredicate>
typename iterator_traits<InputIt>::difference_type
    Count_if(InputIt first, InputIt last, UnaryPredicate * p)
{
    typename iterator_traits<InputIt>::difference_type ret = 0;
    for (; first != last; ++first) {
        if (p(*first)) {
            ret++;
        }
    }
    return ret;
}

bool even(int i)
{
    return i%2 == 0;
}

int main(int argc, const char * argv[])
{
    vector<int> v = { 1,2,3,4,5,6,7,8,9,0};

    int total = 0;
    //cout << Count_if(v.begin(),v.end(),[](int x) { return x%2 == 0; }) << endl;
    //cout << Count_if(v.begin(),v.end(),[&total](int x) { ++total; return x%2 == 0; }) << endl;
    cout << Count_if(v.begin(),v.end(),even) << endl;

}
