On 11/22/19 4:04 AM, Jacob Carlborg wrote:
On Thursday, 21 November 2019 at 20:44:19 UTC, Steven Schveighoffer wrote:
I thought I could do typeid(Class).name to get the class name that will be returned at runtime if you did typeid(instance).name. But it's not accessible at compile-time.

What compile-time string should I use for instance in a constructed switch statement? I'm trying to implement serialization and deserialization of classes, but I really would like to avoid using a class enum if possible, since the type id is already there and generated by the compiler.

I solved that by storing the class info as the key in an associative array [1]. But it looks like Adam's solution will work as well.

If you ideas, you can always have a look at Orange.

[1] https://github.com/jacob-carlborg/orange/blob/90f1dbb0097ba4a319805bfb7d109f7038418ac6/orange/serialization/Serializer.d#L241-L262

Thanks for all the replies, guys. Annoying that the compiler has generated these names but doesn't make them accessible at compile-time.

-Steve

Reply via email to