#include <iostream>
class A {};
class B {};
class A1 {};
class B1 {};
template<class A, class B, class extra = void /* Enable/disable specialization through SFINAE */>
class Class { public: void hello() {std::cout << "Base" << std::endl;} };
template<class B> class Class<A1, B> { public: void hello() {std::cout << "First" << std::endl;} };
template<class A> class Class<A, B1, typename std::enable_if<!std::is_same<A, A1>::value>::type> { public: void hello() {std::cout << "Second" << std::endl;} };
int main()
{
Class<A1,B1> obj;// The first one is picked up
obj.hello();
Class<A,B1> obj2; // The second one is picked up
obj2.hello();
Class<A,B> obj3; // Base
obj3.hello();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgQSB7fTsKY2xhc3MgQiB7fTsKY2xhc3MgQTEge307CmNsYXNzIEIxIHt9OwoKdGVtcGxhdGU8Y2xhc3MgQSwgY2xhc3MgQiwgY2xhc3MgZXh0cmEgPSB2b2lkIC8qIEVuYWJsZS9kaXNhYmxlIHNwZWNpYWxpemF0aW9uIHRocm91Z2ggU0ZJTkFFICovPgpjbGFzcyBDbGFzcyB7IHB1YmxpYzogdm9pZCBoZWxsbygpIHtzdGQ6OmNvdXQgPDwgIkJhc2UiIDw8IHN0ZDo6ZW5kbDt9IH07Cgp0ZW1wbGF0ZTxjbGFzcyBCPiBjbGFzcyBDbGFzczxBMSwgQj4geyBwdWJsaWM6IHZvaWQgaGVsbG8oKSB7c3RkOjpjb3V0IDw8ICJGaXJzdCIgPDwgc3RkOjplbmRsO30gfTsKdGVtcGxhdGU8Y2xhc3MgQT4gY2xhc3MgQ2xhc3M8QSwgQjEsIHR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPCFzdGQ6OmlzX3NhbWU8QSwgQTE+Ojp2YWx1ZT46OnR5cGU+IHsgcHVibGljOiB2b2lkIGhlbGxvKCkge3N0ZDo6Y291dCA8PCAiU2Vjb25kIiA8PCBzdGQ6OmVuZGw7fSB9OwoKaW50IG1haW4oKQp7CiAgICAKICBDbGFzczxBMSxCMT4gb2JqOy8vIFRoZSBmaX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