Thread overview
D equivalent of the X macro?
May 02, 2014
H. S. Teoh
May 02, 2014
Jacob Carlborg
May 02, 2014
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 02, 2014
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 02, 2014
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