Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 17, 2020 How to get the name of an object's class at compile time? | ||||
---|---|---|---|---|
| ||||
What I want is something like this: ---- string className(in Object obj) { return obj is null ? "null" : typeid(obj).name; } ---- ...except I want it to work in CTFE. What is the way to do this in D? |
February 17, 2020 Re: How to get the name of an object's class at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nathan S. | On 2/17/20 2:28 AM, Nathan S. wrote: > What I want is something like this: > > ---- > string className(in Object obj) { > return obj is null ? "null" : typeid(obj).name; > } > ---- > > ...except I want it to work in CTFE. What is the way to do this in D? https://issues.dlang.org/show_bug.cgi?id=7147 It's not doable. It really should be. -Steve |
February 17, 2020 Re: How to get the name of an object's class at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, 17 February 2020 at 18:49:55 UTC, Steven Schveighoffer wrote: > On 2/17/20 2:28 AM, Nathan S. wrote: >> What I want is something like this: >> >> ---- >> string className(in Object obj) { >> return obj is null ? "null" : typeid(obj).name; >> } >> ---- >> >> ...except I want it to work in CTFE. What is the way to do this in D? > > https://issues.dlang.org/show_bug.cgi?id=7147 > > It's not doable. It really should be. > > -Steve Upon seeing this I just implemented typeid(stuff).name; https://github.com/dlang/dmd/pull/10796 With any luck this will be possible in the next release ;) |
February 18, 2020 Re: How to get the name of an object's class at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Monday, 17 February 2020 at 22:34:31 UTC, Stefan Koch wrote:
>
> Upon seeing this I just implemented typeid(stuff).name;
>
> https://github.com/dlang/dmd/pull/10796
>
> With any luck this will be possible in the next release ;)
Can this work using `stuff.classinfo.name` too ?
This is the same as `typeid(stuff).name`
|
February 18, 2020 Re: How to get the name of an object's class at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Tuesday, 18 February 2020 at 03:33:21 UTC, Basile B. wrote:
> On Monday, 17 February 2020 at 22:34:31 UTC, Stefan Koch wrote:
>>
>> Upon seeing this I just implemented typeid(stuff).name;
>>
>> https://github.com/dlang/dmd/pull/10796
>>
>> With any luck this will be possible in the next release ;)
>
> Can this work using `stuff.classinfo.name` too ?
> This is the same as `typeid(stuff).name
Currently no. It's represented differently in the end tree.
|
Copyright © 1999-2021 by the D Language Foundation