Passing Appender by value

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Jun 22 06:34:22 PDT 2013


I just learned today that passing Appender by value does not have the
semantics I thought it would:

-----
import std.array;
import std.stdio;

void call(Appender!(int[]) buffer)
{
    buffer.put(1);
}

void main()
{
    Appender!(int[]) buffer;
    writeln(buffer.data);  // writes [], it's empty
}
-----

Is this a bug? If not, shouldn't we introduce a disabled copy
constructor to force passing Appender by ref to functions to avoid
this type of user bug?

I can't see how the current behavior is useful to anyone.


More information about the Digitalmars-d-learn mailing list