I have tried to use what has been suggested in this question about SFINAE to detect whether a class implements a member function. Now the example is working on CLang 3.6.0 but not on MSVC 2013. My changes are just substitution of typeof with decltype and definition of struct one, two to have different sizes for sure.
The code I am using is the following:
#include <iostream>
struct Hello
{
int helloworld()
{
return 0;
}
};
struct Generic {};
// SFINAE test
template <typename T>
class has_helloworld
{
struct one { int x; };
struct two { int x[2]; };
template <typename C> static one test(decltype(&C::helloworld));
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(one) };
};
int
main(int argc, char *argv[])
{
std::cout << has_helloworld<Hello>::value << std::endl;
std::cout << has_helloworld<Generic>::value << std::endl;
return 0;
}
The problem is that this code gives me (on MSVC2013) the result
1
1
instead of the expected (and obtained on CLang 3.6.0)
1
0
Any hints/fixes?
Aucun commentaire:
Enregistrer un commentaire