J
Jonathan Lee
Hey all,
I'm trying to provide fallbacks for a C99 function (hypot in cmath)
using "disable_if". Something like, "if hypot(double, double) is
not provided by cmath, use this instead"
It isn't working. Anyone know how I can wrangle this? Below is my
attempt.
Thanks
--Jonathan
//#include <cmath>
#include <iostream>
using std::cout;
using std::endl;
template<typename T>
struct temp {
typedef T (*myfunctype)(T, T);
static myfunctype myhypot;
};
template<typename T>
typename temp<T>::myfunctype temp<T>::myhypot = 0;
// Can SFINAE work here??
template<>
temp<double>::myfunctype temp<double>::myhypot = hypot;
template<bool B, class T = void>
struct disable_if { typedef T type; };
template<class T>
struct disable_if<false, T> { };
// fallback hypot
template<typename T>
typename disable_if< temp<T>::myhypot , T>::type hypot(T x, T y) {
return sqrt(x * x + y * y); // ya ya, not accurate
}
int main() {
double x = 3.0, y = 5.0;
cout << hypot(x, y) << endl;
return 0;
}
I'm trying to provide fallbacks for a C99 function (hypot in cmath)
using "disable_if". Something like, "if hypot(double, double) is
not provided by cmath, use this instead"
It isn't working. Anyone know how I can wrangle this? Below is my
attempt.
Thanks
--Jonathan
//#include <cmath>
#include <iostream>
using std::cout;
using std::endl;
template<typename T>
struct temp {
typedef T (*myfunctype)(T, T);
static myfunctype myhypot;
};
template<typename T>
typename temp<T>::myfunctype temp<T>::myhypot = 0;
// Can SFINAE work here??
template<>
temp<double>::myfunctype temp<double>::myhypot = hypot;
template<bool B, class T = void>
struct disable_if { typedef T type; };
template<class T>
struct disable_if<false, T> { };
// fallback hypot
template<typename T>
typename disable_if< temp<T>::myhypot , T>::type hypot(T x, T y) {
return sqrt(x * x + y * y); // ya ya, not accurate
}
int main() {
double x = 3.0, y = 5.0;
cout << hypot(x, y) << endl;
return 0;
}