D metaclass stuff vs C++23

Alex sascha.orlov at gmail.com
Mon May 13 10:25:22 UTC 2019


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 ;)


More information about the Digitalmars-d mailing list