Is there a way to determine from two objects const ::std::type_info, name them Band D, if the type described by D is derived from type B?
I ask because I want to erase the type of object that I receive, but later, to check if it can be safely promoted.
void* data;
const ::std::type_info* D;
template<typename D>
void store(D&& object)
{
D = &typeid(object);
data = ::std::addressof(object);
}
template<typename B>
B& load()
{
return *reinterpret_cast<B*>(data);
}
I want to use it like this:
class Base {};
class Derived : Base {};
Derived d;
store(d);
load<Base>();
Thus, it is not practical to use equality comparisons for types. I am sure that this may be possible in the same way that dynamic_cast can understand it. I want that in every case, when I D&could be assigned B&, letting B as an argument of type load()- without knowing Dat this time.