equivalent of typeid(Class).name at compile-time

Jacob Carlborg doob at me.com
Fri Nov 22 09:04:35 UTC 2019


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


More information about the Digitalmars-d-learn mailing list