www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D metaclass stuff vs C++23

reply Russel Winder <russel winder.org.uk> writes:
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 =3D None

   if __name__ =3D=3D '__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?

=20
--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk
May 13
next sibling parent reply Alex <sascha.orlov gmail.com> writes:
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 ;)
May 13
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
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
May 13
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 5/13/19 10:06 AM, 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?
I replied with a no-brainer equivalent.
May 13