Check whether string value represents a type

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 21 07:44:23 PDT 2017


On 7/21/17 10:21 AM, Timoses wrote:
> I'd love to check whether a string value is the name of a type at run-time.
> 
> E.g.:
> 
> 
> string a = "int";
> string b = "im no type";
> assert( isStringType(a) );
> assert( !isStringType(b) );
> 
> or
> 
> struct TestStruct
> {
>      int test;
> }
> 
> string t = "TestStruct";
> assert( isStringType(t) );
> 
> 
> Is anything like this possible?
> 
> The goal is to identify whether a string represents a custom type within 
> a package. I'm also trying to iterate over all modules within the 
> package to get the struct name. However, that seems like a struggle...
> 
> Any ideas?..

In order to do this, the list of types must be stored somewhere to 
compare with at runtime.

At this time, this is not done. You could potentially do this with the 
RTInfo template, but it would have to be part of a custom druntime.

-Steve


More information about the Digitalmars-d-learn mailing list