D equivalent of the X macro?

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Thu May 1 17:52:51 PDT 2014


On 05/02/14 02:22, H. S. Teoh via Digitalmars-d wrote:
> I was reading this article of Walter's:
> 
> 	http://www.drdobbs.com/cpp/the-x-macro/228700289
> 
> Which is a neat trick that I wish I'd known back when I was writing
> C/C++. But the thought crossed my mind: what's the D equivalent of the X
> macro, since D doesn't have macros? Any ideas?

Enums, mixins and CTFE.

For example, create an enum array, even an associative one, iterate over
the data at CT, generate the necessary code (and/or data), then mix it all in
at the right place.

artur


More information about the Digitalmars-d mailing list