automate tuple creation
forkit
forkit at gmail.com
Fri Jan 21 04:08:33 UTC 2022
On Friday, 21 January 2022 at 03:57:01 UTC, H. S. Teoh wrote:
>
> std.array.appender is your friend.
>
> T
:-)
// --
void ProcessRecords
(in int[][int][] recArray, const(string) fname)
{
auto file = File(fname, "w");
scope(exit) file.close;
Appender!string bigString = appender!string;
bigString.reserve(recArray.length);
debug { writefln("bigString.capacity is %s",
bigString.capacity); }
void processRecord(const(int) id, const(int)[] values)
{
bigString ~= id.to!string ~ values.format!"%(%s,%)" ~
"\n";
}
foreach(ref const record; recArray)
{
foreach (ref rp; record.byPair)
{
processRecord(rp.expand);
}
}
file.write(bigString[]);
}
// ---
More information about the Digitalmars-d-learn
mailing list