June 22, 2013 Passing Appender by value | ||||
|---|---|---|---|---|
| ||||
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.
| ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply