0

Is there a way to use something like std::is_base_of based on the strings generated by typedid(...).name(), and not on the types themselves?

In extenso, given something like:

class A {...};
class B: public A {...};

A a;
B b;

std::string sa = typeid(a).name;
std::string sb = typeid(b).name;

I would need something like this, at runtime:

if( std::is_base_of(sa, sb) )
{...}

This is related to object serialization in files.

Is there a way to perform this (without boost)?

Jacques
  • 301
  • 2
  • 13
  • @cigien. As written, this is related to serialization of object structures into a file (and reload). – Jacques Sep 14 '20 at 17:12
  • You can't rely on `typeid(...).name` in any way. This value can change between compilers, between versions of the same compiler, between two compiliations and even between two runs of one and the same program. Or it can be identical for multiple types or just a random garbage value. I'm not really sure what worth this name actually has. – Lukas-T Sep 14 '20 at 17:17
  • @Jacques Can you use other serialization libraries besides boost? There's that wonderful gem [s11n](http://www.s11n.net/). A bit older, but overall lightweight and very customizable regarding the output formats. I've been using it a (longer) while ago in the embedded programming field, where boost was a _no go_. – πάντα ῥεῖ Sep 14 '20 at 17:22

0 Answers0