core.reflect vs c++ reflection

bauss jj_1337 at live.dk
Tue Sep 28 06:43:39 UTC 2021


On Monday, 27 September 2021 at 13:12:32 UTC, WebFreak001 wrote:
> 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"`

Yeah, I really wish we had an alternative to stringof like 
nameof. I often forgot that aliases don't work well with it, as 
displayed here :)


More information about the Digitalmars-d mailing list