I have below code that I want TestEnableIf with different specialization to have different print function, but it didn't work out as planned, with error as below.
struct myStruct;
struct notMyStruct;
template<typename T> struct TestEnableIf
{
template<typename boost::enable_if< boost::is_same<myStruct, T>, int >::type = 0> void print()
{
std::cout << "this is my struct" << std::endl;
}
template<typename boost::enable_if< boost::is_same<notMyStruct, T>, int>::type=0> void print()
{
std::cout << "This is not my struct" << std::endl;
}
};
static void testIsSame()
{
TestEnableIf<myStruct> testEnable;
testEnable.print();
TestEnableIf<notMyStruct> testNotEnable;
testNotEnable.print();
}
../src/testBoostGeneric.h:39:90: error: no type named ‘type’ in ‘struct boost::enable_if, int>’ template, int>::type=0> void print() ^ ../src/testBoostGeneric.h: In instantiation of ‘struct TestEnableIf’: ../src/testBoostGeneric.h:53:29:
required from here ../src/testBoostGeneric.h:34:90: error: no type named ‘type’ in ‘struct boost::enable_if, int>’ template, int >::type = 0> void print()
What I don't understand is, should sfinae mean specialization failure is not an error, then why should the compiler complain about the failure?