How to create a mutable array of strings?
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 17 02:39:21 PDT 2015
I remembered code Ali Çereli. It really helped:
http://forum.dlang.org/thread/ulhtlyxxclihaseefrot@forum.dlang.org#post-mihl6m:241che:241:40digitalmars.com
-----
import std.stdio, std.traits, std.range, std.algorithm;
auto deepDup(A)(A arr)
if (isArray!A)
{
static if (isArray!(ElementType!A)) {
return arr.map!(a => a.deepDup).array;
} else {
return arr.dup;
}
}
void main() {
auto s = ["foo", "bar"].deepDup;
s[1][1] = 't';
writeln(s);
}
-----
http://rextester.com/QBFH12695
P.S. Need to enable deepDup in Phobos.
More information about the Digitalmars-d-learn
mailing list