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

VitaliiY yvitaliy1980 at yandex.ru
Wed Jun 16 05:48:21 UTC 2021


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: ADDBITS(varA, varB) becomes
> mixin(ADDBITS!("varA", "varB"));
> `
>
> [...]

Thank you, Dennis. I tried with this kind of mixin, but a, b - 
are type of 'int so it's confusing to use them as mixin arguments.


More information about the Digitalmars-d-learn mailing list