Enum template with mixin, need 'this'

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 24 09:40:58 PST 2014


On Wed, 24 Dec 2014 17:05:45 +0000
Meta via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141224/fb50cf77/attachment.sig>


More information about the Digitalmars-d-learn mailing list