Re: How to translate this C macro to D mixin/template mixin?

2021-06-16 Thread Tejas via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 05:48:21 UTC, VitaliiY wrote: On Tuesday, 15 June 2021 at 12:39:40 UTC, Dennis wrote: On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote: [...] ```D enum string ADDBITS(string a, string b) = ` { bitbuffer = (bitbuffer<<(`~a~`))|((`~b~`)&((1<<`~a~`)-1));

Re: How to translate this C macro to D mixin/template mixin?

2021-06-15 Thread VitaliiY via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 12:39:40 UTC, Dennis wrote: On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote: [...] ```D enum string ADDBITS(string a, string b) = ` { bitbuffer = (bitbuffer<<(`~a~`))|((`~b~`)&((1<<`~a~`)-1)); numbits += (`~a~`); mixin(STOREBITS); }`; // on use:

Re: How to translate this C macro to D mixin/template mixin?

2021-06-15 Thread VitaliiY via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 12:38:15 UTC, Ali Çehreli wrote: On 6/15/21 5:18 AM, VitaliiY wrote: > STOREBITS and ADDBITS use variables defined in STARTDATA If possible in your use case, I would put those variables in a struct type and make add() a member function. However, a similar type alre

Re: How to translate this C macro to D mixin/template mixin?

2021-06-15 Thread Dennis via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote: It's simple with STARTDATA as mixin, but STOREBITS and ADDBITS use variables defined in STARTDATA scope, so I can't understand how to do mixin template with it. If the code duplication isn't too bad, consider just expanding the C macro

Re: How to translate this C macro to D mixin/template mixin?

2021-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 6/15/21 5:18 AM, VitaliiY wrote: > STOREBITS and ADDBITS use variables defined in STARTDATA If possible in your use case, I would put those variables in a struct type and make add() a member function. However, a similar type already exists as std.bitmanip.BitArray. Ali

How to translate this C macro to D mixin/template mixin?

2021-06-15 Thread VitaliiY via Digitalmars-d-learn
Could anybody help with translation of this C macro to D mixin/mixin template? Here a - unsigned char, b - int. It's simple with STARTDATA as mixin, but STOREBITS and ADDBITS use variables defined in STARTDATA scope, so I can't understand how to do mixin template with it. #define STARTDAT