### my count_if() implementation doesnt work

Hi, I'm having trouble understanding 1 thing so here it is!

1. I created my count_if function
 ``1234567891011`` ``````template int count_if(Iter begin, Iter end, Pred pred){ int sum = 0; for(; begin != end; ++begin){ if(pred(*begin)) sum++; } return sum; }``````

and than wrote simple predicate function
 ``12345`` ``````template bool bigger_than(T val){ if(10 < val) return true; else return false; }``````

The problem is that I'm getting this error
 ``` /home/girts/Desktop/exercises/chapter_21/exercise_4/main.cpp:40: error: no matching function for call to 'count_if(std::vector::iterator, std::vector::iterator, )' std::cout << count_if(vec.begin(), vec.end(), bigger_than) << std::endl; ^ ```

If I remove template stuff from my function than its running fine. Also works fine with function object.

Full code if someone wants to run it
 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` ``````/* 4. Implement count_if() yourself! Test it !*/ #include #include template int count_if(Iter begin, Iter end, Pred pred){ int sum = 0; for(; begin != end; ++begin){ if(pred(*begin)) sum++; } return sum; } template bool bigger_than(T val){ if(10 < val) return true; else return false; } struct biger{ int val; biger(int v) : val{v}{} bool operator()(int V){ if(val < V) return true; else return false; } }; int main(){ std::vector vec {8, 12, 9, 5, 33, 4, 5, 4, 1, 20, 18, 17, 28, 1}; //std::cout << count_if(vec.begin(), vec.end(), biger(10)) << std::endl; std::cout << count_if(vec.begin(), vec.end(), bigger_than) << std::endl; } ``````
You forgot to specify what instantiation of bigger_than you want to use.
 `` `` ``std::cout << count_if(vec.begin(), vec.end(), bigger_than) << std::endl;``
Last edited on
Try

`std::cout << count_if(vec.begin(), vec.end(), bigger_than<int>) << std::endl;`

for line 40.

Andy
Ohh, thanks guys so much :)