www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Convert this C define to D

reply Regan Heath <regan netmail.co.nz> writes:
Hi all,

I have this C macro:

#define STACK_OF(type) STACK

usage:

struct foo {
  STACK_OF(Bob) bobStack;
}

lets ignore the fact that the replacement STACK doesn't include with the type
it was given, in this case/stage it's not important.

I feel like I should be able to replace this C macro with a template/mixin of
some kind but as templates/mixins aren't my strongest d-foo (kungfoo) technique
I figured I had best ask for opinions.

Regan
May 22 2007
parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Regan Heath wrote:
 Hi all,
 
 I have this C macro:
 
 #define STACK_OF(type) STACK
 
 usage:
 
 struct foo {
   STACK_OF(Bob) bobStack;
 }
 
 lets ignore the fact that the replacement STACK doesn't include with the type
it was given, in this case/stage it's not important.
 
 I feel like I should be able to replace this C macro with a template/mixin of
some kind but as templates/mixins aren't my strongest d-foo (kungfoo) technique
I figured I had best ask for opinions.
 
 Regan
Assuming that STACK is an actual type... template STACK_OF(type) { alias STACK STACK_OF; } -- Daniel -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
May 22 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
Daniel Keep Wrote:
 Regan Heath wrote:
 Hi all,
 
 I have this C macro:
 
 #define STACK_OF(type) STACK
 
 usage:
 
 struct foo {
   STACK_OF(Bob) bobStack;
 }
 
 lets ignore the fact that the replacement STACK doesn't include with the type
it was given, in this case/stage it's not important.
 
 I feel like I should be able to replace this C macro with a template/mixin of
some kind but as templates/mixins aren't my strongest d-foo (kungfoo) technique
I figured I had best ask for opinions.
 
 Regan
Assuming that STACK is an actual type... template STACK_OF(type) { alias STACK STACK_OF; }
So, using the above this: struct foo { STACK_OF(Bob) bobStack; } results in/becomes/is equivalent to this: struct foo { STACK bobStack; } ? Yes, STACK is a type, a structure which has previously been defined. Regan
May 22 2007
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Regan Heath wrote:
 Daniel Keep Wrote:
[snip]
 Assuming that STACK is an actual type...

 template STACK_OF(type)
 {
     alias STACK STACK_OF;
 }
So, using the above this: struct foo { STACK_OF(Bob) bobStack; } results in/becomes/is equivalent to this: struct foo { STACK bobStack; } ? Yes, STACK is a type, a structure which has previously been defined.
Almost. You'd have to do this: --- struct foo { STACK_OF!(Bob) bobStack; } --- Note the '!'.
May 22 2007