[Cpp]
// T cocould converted to U?
Template <typename T, typename U>
Class Conversion
{
Private:
Typedef char Small;
Struct Big {char big [2];};
Static Small _ helper_fun (U );
Static Big _ helper_fun (...);
Static T _ make_T ();
Public:
Enum {
Exists = (sizeof (_ helper_fun (_ make_T () = sizeof (Small )),
Exists2Way = (Exists & Conversion <U, T >:: Exists ),
Same = false
};
};
// Partial specialization for "same type"
Template <typename T>
Class Conversion <T, T>
{
Public:
Enum {
Exists = true,
Exists2Way = true,
Same = true
};
};
// T is subclass of U?
Template <typename T, typename U>
Class IsSubclass
{
Public:
Enum {
Result = Conversion <T *, U *>: Exists
};
};
// T cocould converted to U?
Template <typename T, typename U>
Class Conversion
{
Private:
Typedef char Small;
Struct Big {char big [2];};
Static Small _ helper_fun (U );
Static Big _ helper_fun (...);
Static T _ make_T ();
Public:
Enum {
Exists = (sizeof (_ helper_fun (_ make_T () = sizeof (Small )),
Exists2Way = (Exists & Conversion <U, T >:: Exists ),
Same = false
};
};
// Partial specialization for "same type"
Template <typename T>
Class Conversion <T, T>
{
Public:
Enum {
Exists = true,
Exists2Way = true,
Same = true
};
};
// T is subclass of U?
Template <typename T, typename U>
Class IsSubclass
{
Public:
Enum {
Result = Conversion <T *, U *>: Exists
};
};