scope exit in mixin template

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 8 11:48:01 PDT 2014


On Sunday, 8 June 2014 at 18:28:25 UTC, Byron wrote:
>
> Can we not use scope(..) in a mixin template?
>
> struct bar {}
> bar* c_make() { return new bar(); }
> void c_free(bar* b) { b = null; }
>
> mixin template Foo() {
>   auto b = c_make;
>   scope(exit) if(b) c_free(b);
> }
>
> void main() {
>   mixin Foo;
> }
>
> I get Error: Declaration expected, not '('
>
> -Byron

Mixin templates can only insert declarations, not arbitrary code. 
When it sees "scope", it's expecting it to be the attribute, not 
the declaration.


More information about the Digitalmars-d-learn mailing list