Re: SFINAE compiler problem?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



> I hope it helps you find a good solution for a general case.


apparently it helped :)
the following code seems to work everywhere. can you test in VC8?




struct NO {};

struct myclass
{
myclass& f1(int)
{
return *this;
}

myclass& f1(double)
{
return *this;
}

};



template <typename T, typename X>
struct f1_specialized_for
{
template <X& (X::*pointer)(T)>
struct yes { char dummy_[2]; };

typedef char no;

template <typename Y>
static yes< &Y::f1 > test(Y*);

static no test(...);

static X* ptr();

static const bool value = sizeof(test(ptr()))>1;
};





template <bool B>
struct t_assert
{};

template <>
struct t_assert<false>;



int main(int argc, char* argv[])
{
t_assert< f1_specialized_for<int, myclass>::value > A1;
t_assert< !f1_specialized_for<NO, myclass>::value > A2;
t_assert< f1_specialized_for<double, myclass>::value > A3;

return 0;
}


.



Relevant Pages