core.reflect vs c++ reflection

WebFreak001 d.forum at webfreak.org
Mon Sep 27 13:12:32 UTC 2021


On Monday, 27 September 2021 at 08:39:45 UTC, Stefan Koch wrote:
> On Monday, 27 September 2021 at 07:32:48 UTC, bauss wrote:
>>
>> Yeah I figured it wouldn't work that easily.
>>
>> In this case yeah "E" wouldn't be a problem but if it was 
>> "ThisTypeName" you might end up with a typo.
>
> Yes, but you can typo ThisTypeName whether you type it with 
> quotes around it or without.
> It's still an identifier. Which may not be Identifying anything 
> if it's mistyped.
> The reason why I am using a string is that I wanted to avoid 
> having to introduce a special expression. see c++ `reflexpr`

If it's mistyped, the compiler will complain that it doesn't exist

When it's an identifier, IDE refactorings (automated renaming) 
will find it, while it wouldn't find it in a string, especially 
the more generic the name is (which is common for template types 
`T`)

C# has `nameof(T)` which just returns `"T"` or for 
`nameof(Foo.T)` it also just returns `"T"`


More information about the Digitalmars-d mailing list