I’m trying to pass a specific overload of std::isfinite()
to a function, but GCC refuses:
0.cpp:9:24: error: no matching function for call to ‘all_of(std::array<double, 2>::const_iterator, std::array<double, 2>::const_iterator, <unresolved overloaded function type>)’
9 | return !std::all_of(a.begin(), a.end(), std::isfinite<double>);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here’s the source:
#include <algorithm>
#include <array>
#include <cmath>
int main()
{
auto const a = std::array<double, 2>{{0.0, 1.0}};
return !std::all_of(a.begin(), a.end(), std::isfinite<double>);
}
Why does it consider std::isfinite<double>
to be an unresolved overloaded function type, and is there a solution simpler than wrapping in a lambda function of my own? I’d prefer not to have to write [](double x){ return std::isfinite(x); }
if I don’t need to.
If it matters, I see the same symptom with all the standards versions I tried -std=c++11
, -std=c++17
and -std=c++23
.