Thread overview | |||||
---|---|---|---|---|---|
|
May 02, 2014 D equivalent of the X macro? | ||||
---|---|---|---|---|
| ||||
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 Re: D equivalent of the X macro? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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 Re: D equivalent of the X macro? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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 |
Copyright © 1999-2021 by the D Language Foundation