D metaclass stuff vs C++23
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon May 13 11:03:35 UTC 2019
On 5/13/19 11:25 AM, Alex wrote:
> On Monday, 13 May 2019 at 09:06:07 UTC, Russel Winder wrote:
>> Hi,
>>
>> In the "show what can be done, not what should be done" category,
>> someone has done a C++ version of Hello World using the up-coming
>> metaclass stuff:
>>
>> https://twitter.com/Cor3ntin/status/1127210941718962177
>>
>> I immediately (once I knew about it) replied with the Python version:
>>
>> https://twitter.com/russel_winder/status/1127859587393163265
>>
>>
>> class Hello: pass
>>
>> World = None
>>
>> if __name__ == '__main__':
>> print(" ".join([item for item in dir() if not
>> item.startswith("_")]))
>>
>>
>> but clearly a better competitor would be a D version. Anyone done this
>> sort of thing, i.e. compile time metaclass manipulation?
>
> Something like this is possible (for a long time now, I think...),
>
> ´´´
> import std.format;
> struct Hello;
> int World;
>
> pragma(msg, format!"%s %s"(__traits(allMembers, mixin(__MODULE__))[$-2
> .. $]));
> ´´´
>
> but I'm sure, more cool versions are possible ;)
The idea is to just provide something simple that doesn't introduce a
bunch of stuff. Here's what I wrote:
https://twitter.com/incomputable/status/1127891251666223105
More information about the Digitalmars-d
mailing list