I just ran into a compilation failure when porting some code from VS2013 to GGC 4.9 and Clang 3.5 (using libC ++). Code Essence
#include <cmath> struct Foo { operator double() const { return( 101.0 ); } // Implicit conversion to double }; int main( int, char** ) { Foo foo; std::exp( foo ); // Compiles std::isfinite( foo ); // Does not return( 0 ); }
I believe that the isfinite call isfinite not compile, because the isfinite funtion function in cmath has a return type declared as:
typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
and because Foo not is_arithmetic , isfinite is removed from the overload set. The same applies to isfinite friends like isnan . So my question is whether this is expected.
Does the standard isfinite to these arguments with functions such as isfinite , such as actually directly double or float , in contrast to the fact that they are implicitly converted to them?
Also, I'm a little unsure why std::is_arithmetic not std::is_floating_point , isn't is_arithmetic implies isfinite for integers?
As an additional question, what is the best way to specify a constraint such as is_convertible_to_floating_point?
source share