-1

I have two pointers std::type_info t1 and std::type_info t2. How can I find out if t1 is a subtype of t2? I have no other information available.

SHolz
  • 1
  • Did you try [`std::is_base_of`](http://en.cppreference.com/w/cpp/types/is_base_of)? Where did the typeinfo come from? – πάντα ῥεῖ Feb 17 '17 at 21:27
  • A `type_info` only represents information about the name of types and some implementation-defined ordering information. If two `subtype`s compare equal, they correspond to the same actual type. However, there is no way to get information about other relationships (such as subtyping) between the actual types. – Peter Feb 17 '17 at 21:31
  • `std::type_info t1` is the type of an exception, which I intercept. – SHolz Feb 17 '17 at 21:31
  • @Peter that surprises me, how does gcc or clang implement catch internally then? – SHolz Feb 17 '17 at 21:32
  • If you catch an exception, then surely you have a pointer to the exception object, no? – IInspectable Feb 17 '17 at 21:33
  • There is no requirement that an implementation only use information in a `type_info` to implement exception handling. – Peter Feb 17 '17 at 21:34

1 Answers1

1

I have two pointers std::type_info t1 and std::type_info t2. How can I find out if t1 is a subtype of t2? I have no other information available

The standard does not define any relationships between two instances of std::type_info. Unless your platform provides additional information, you cannot determine whether the type corresponding t1 is a subtype of the type corresponding to t2.

R Sahu
  • 204,454
  • 14
  • 159
  • 270