Why does this mixin fail to compile?
Lance Bachmeier
no at spam.net
Wed Jul 3 11:57:58 UTC 2024
On Wednesday, 3 July 2024 at 03:52:41 UTC, Steven Schveighoffer
wrote:
> ```d
> mixin template implement()
> {
> mixin(() {
> // ctfe new array is basically the same as static array
> char[] buffer = new char[4096];
> int pos = 0;
>
> void append(string str)
> {
> buffer[pos .. pos + str.length] = str[];
> pos += str.length;
> }
>
> append("void* ctx;");
> return buffer[0 .. pos];
> }());
> }
> ```
>
> And yes, it is faster to do this than appending. But you have
> to do a *lot* of it to make a huge difference.
What about creating an array of strings and then using join? One
obvious problem with this solution is the requirement to specify
the size of `buffer`.
More information about the Digitalmars-d-learn
mailing list