std.array : appender woes

abad via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 16 00:47:03 PDT 2016


import std.array : appender;
import std.stdio : writeln;

void main() {
     auto app = appender!(char[]);
     app.put('x');
     auto foo = app.data;
     app.clear; // done, start a new array
     app.put('y');
     writeln(foo);
}

This prints out 'y'. It's not surprising because what I suppose 
app.data is doing is just returning a slice of the dynamic array. 
Clear() resets the counter of current position. But this behavior 
is confusing in practical use, IMHO.

Should calling clear in your opinion guarantee that a new array 
gets allocated?



More information about the Digitalmars-d-learn mailing list