On Wednesday, 24 December 2014 at 17:41:09 UTC, ketmar via Digitalmars-d-learn wrote:
On Wed, 24 Dec 2014 17:05:45 +0000
Meta via Digitalmars-d-learn <[email protected]> wrote:

So `if (isSet!bit1)` becomes `if (cast(bool)(embeddedTest.bits & bit1)`. That doesn't work, however. I get an error message saying "need 'this' for 'bits' of type 'int'". Is there a way to make this work, or am I stuck with the uglier mixin at the usage site?

i don't think that you can cheat like this. ;-)

templates aren't macros, and `mixin` inside the template works
immediately. i.e. it's trying to *execute* the mixined code in
compile time. so your template with `mixin` in it tries to check
`embedded.bits` in *compile* time, and then complains about missing
'this', as it should.

i don't think that you can do c-like macros in D.

Hmm, I confused myself over when the expression is interpreted. I got it into my head that the template expansion would somehow delay interpretation of the expression so it could be picked up at runtime, but of course `enum` forces it to be CTFE'd.

Reply via email to