I have the following piece of code, that gives an error on the first usage form of pred2. I was hoping if someone could explain why this particular usage is incorrect, as I think pred3 usage is similar.
#include <algorithm>
bool pred1(const int&) { return true; }
template<typename T>
bool pred2(const T&) { return true; }
struct pred3
{
template<typename T>
bool operator()(T&) { return true; }
};
int main()
{
int A[] = { 2, 0, 4, 6, 0, 3, 1, -7 };
const int N = sizeof(A) / sizeof(int);
std::count_if(A, A + N, &pred1); //ok
std::count_if(A, A + N, &pred2); //error
std::count_if(A, A + N, &pred2<int>); //ok
std::count_if(A, A + N, pred3()); //ok
return 0;
}