Is it possible to use Type Erasure at all to create objects that encapsulate an arbitrary type (let it call it ErasedType), and it can be requested at runtime to determine if another arbitrary type can be converted Tto ErasedType?
Thinking about it, I do not think it is possible - even if it seems that it is potentially possible in theory. The compiler will know what types Twe are trying to compare with ErasedType, and therefore can generate the necessary code before running. The problem is that in practice, there does not seem to be ANY way to pass the type of the template parameter from the base class instance to the subclass instance.
For instance:
struct FooBase
{
template <class TestType>
bool is_convertible()
{
return call_derived();
}
protected:
virtual bool call_derived() = 0;
template <class ErasedType>
void base_class_function() { }
};
template <class ErasedType>
struct Foo : public FooBase
{
bool call_derived()
{
}
};
, , - :
FooBase* f = new Foo<int>();
bool res1 = f->is_convertible<double>();
bool res2 = f->is_convertible<long>();
bool res3 = f->is_convertible<std::string>();
, FooBase::is_convertible , TestType ErasedType , , of std::is_convertible<TestType, ErasedType>::value
, ?