А зачем std::count_if возвращает тип iterator_traits<InputIt>::difference_type, а не size_t? Из-за этой фигни count_if не компилится с кастомными итераторами, хотя сама имплементация нормальная, проблема только в типе результата.
The number of increments needed to go from first to last. The value may be negative if random-access iterators are used and first is reachable from last (since C++11)