Create and overloaded function for Numeric and Integer Vector

I know that we can't overload a C++ function in R according to this Q/A. But sometime we need it. The solution proposed to make a dispatcher in the question linked seems a bit overkilled to me (using templates and switches). I'm wondering if there is an elegant solution for simple problems.

So here a simple problem. x is a vector of int or a vector of double. sum(x == y) can be written in a faster and memory optimized way in C++.

int int_count_equal(IntegerVector x, int y)
{
 return std::count(x.begin(), x.end(), y);
}

and

int num_count_equal(NumericVector x, double y)
{
 return std::count(x.begin(), x.end(), y);
}

The two functions have the same body. It does not make sense and it is not convenient to have two functions. How can we make a dispatcher in a single function count_equal without writing twice the same code?