The following code compiles and generates a call std::isnan, see here
#include <iostream>
#include <cmath>
namespace foo {
template<class T>
inline bool isnan (T x)
{
std::cout << "foo::isnan" << std::endl;
return true;
}
}
using foo::isnan;
using std::isnan;
int main () {
std::cout << isnan(5.5f) << std::endl;
return 0;
}
Why is this feature not ambiguous?
Looking at cmath.h, I see:
template<typename _Tp>
inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
int>::__type
isnan(_Tp __f)
{
typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
return __builtin_isnan(__type(__f));
}
which, at least for me, doesn’t look like necessarily the best match.
The motivation for this question is:
I found these lines of code (perhaps the result of some Eclipse auto-generation)
using std::isnan
using boost::math::isnan
And I was wondering why the compiler would not generate at least a warning.
source
share