Passing Appender by value

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


On 6/22/13, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> 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
> }
> -----

WRONG example, there's a missing call there, I meant:

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

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

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


More information about the Digitalmars-d-learn mailing list