Why does this mixin fail to compile?

ryuukk_ ryuukk.dev at gmail.com
Mon Jul 1 12:26:21 UTC 2024


Ok, i'll just do it and benchmark at the end

Another question:


Why doesn't this work?:


```D
mixin implement;

mixin template implement()
{
     char[4096] buffer = 0;
     int pos = 0;

     void append(string str)
     {
         buffer[pos .. pos + str.length] = str[];
         pos += str.length;
     }

     append("void* ctx;");
     mixin(cast(string) buffer[0 .. pos]);
}
```


```
onlineapp.d(13): Error: unexpected `(` in declarator
onlineapp.d(13): Error: basic type expected, not `"void* ctx;"`
onlineapp.d(13): Error: found `"void* ctx;"` when expecting `)`
onlineapp.d(13): Error: no identifier for declarator 
`append(_error_)`
onlineapp.d(13): Error: semicolon expected following function 
declaration, not `)`
onlineapp.d(13): Error: declaration expected, not `)`
```


More information about the Digitalmars-d-learn mailing list