#include
<iostream>
using
namespace
std;
namespace
__inner
{
template
<typename _T> char fun(_T*);
template
<typename _T> long fun(...);
}
template
<typename _Base, typename _Sub>
struct
is_same_type
{
enum
{value = sizeof(char) == sizeof(__inner::fun<_Base>((_Sub*)0)) };
};
class
ISupportInitialize
{
public
:
void
Initialize() {cout<<"ISupportInitialize Initialize"<<endl;};
};
class
Foo:
public
ISupportInitialize
{
public
:
void
Initialize(){ cout<<"Foo Initialize"<<endl; };
};
template
<bool>
class
dispatcher
{
public
:
template
<typename _T>
dispatcher(_T& r){}
};
template
<> class dispatcher<true>
{
public
:
template
<typename _T>
dispatcher(_T& r)
{
r.Initialize();
}
};
template
<class T> void function( T t )
{
(dispatcher<is_same_type<ISupportInitialize, T>::value>(t));
}
int
main()
{
ISupportInitialize is;
Foo x;
int
y=0;
function(is);
function(x);
function(y);
}