#include <iostream>
struct My
{
typedef int foo;
};
struct My2
{
};
template<typename T, typename I=int> struct call_traits {
static void Bar(...)
{
std::cout << "...\n";
}
};
template<typename T> struct call_traits<T, typename T::foo> {
static void Bar(const T&, int z=typename T::foo())
{
std::cout << "My\n";
}
};
template<typename T> void Bar(const T& t)
{
call_traits<T>::Bar(t);
}
int main()
{
My my;
Bar(my); // OK
My2 my2;
Bar(my2); // Still OK
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IE15CnsKICAgdHlwZWRlZiBpbnQgZm9vOwp9OwoKc3RydWN0IE15Mgp7Cn07Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBULCB0eXBlbmFtZSBJPWludD4gc3RydWN0IGNhbGxfdHJhaXRzIHsKCXN0YXRpYyB2b2lkIEJhciguLi4pCgl7CgkJc3RkOjpjb3V0IDw8ICIuLi5cbiI7Cgl9Cn07Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPiBzdHJ1Y3QgY2FsbF90cmFpdHM8VCwgdHlwZW5hbWUgVDo6Zm9vPiB7CglzdGF0aWMgdm9pZCBCYXIoY29uc3QgVCYsIGludCB6PXR5cGVuYW1lIFQ6OmZvbygpKQoJewoJCXN0ZDo6Y291dCA8PCAiTXlcbiI7Cgl9Cn07Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPiB2b2lkIEJhcihjb25zdCBUJiB0KQp7CgljYWxsX3RyYWl0czxUPjo6QmFyKHQpOwp9CgppbnQgbWFpbigpIAp7CiAgICBNeSBteTsKICAgIEJhcihteSk7IC8vIE9LCiAgICBNeTIgbXkyOwogICAgQmFyKG15Mik7IC8vIFN0aWxsIE9LCiAgICByZXR1cm4gMDsKfQ==