sfinae will nicht
-
hi
template<class T> class subval { private: subval(); struct yes; struct no; template <class U> inline yes Check(const U* = &T::Value) const { } template <class U> inline no Check(const U* = 0) const { } public: static const bool Value = sizeof(Check()) == sizeof(yes); }; template<class T> struct subval<T>::yes { char Fill; }; template<class T> struct subval<T>::no { char Fill[2]; };wenn ich dann instanzieren möchte sagt msvc 2008 dass der typ von U nicht hergeleitet werden kann. wie kann man das sonst lösen oder habe ich sfinae falsch verstanden?
-
Sieht nicht uninteressant aus. Woher sollte der Compiler deiner Meinung nach in Zeile 13 ableiten können, was für ein Zeiger das
Uist?
-
Bei mir klappt das da:
#include <iostream> #include <vector> using namespace std; struct Gut{ static int value; }; struct Boese{ }; template<typename T> class HasValue { template<typename U> static char check(...); template<typename U> static char (&check(char(*)[sizeof(U::value)]))[2]; public: static const bool value=sizeof(check<T>(0))==2; }; int main() { cout<<HasValue<Gut>::value<<'\n'; cout<<HasValue<Boese>::value<<'\n'; }edit: Alle Unleserlichkeit auf eine Zeile konzentriert.