www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D equivalent of the X macro?

reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
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?


T

-- 
When solving a problem, take care that you do not become part of the problem.
May 01 2014
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 01 May 2014 20:22:11 -0400, H. S. Teoh via Digitalmars-d  
<digitalmars-d puremagic.com> 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?
Tuples immediately come to mind. Then a mixin to extract the appropriate tuple indexes. The only issue to overcome is that the mixin has to define the entire structure, whereas in C, you can have the macro only define the data part, not the enclosing structure. -Steve
May 01 2014
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 02/05/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?
The Color example is already handled by D, if I recall correctly. -- /Jacob Carlborg
May 02 2014