How to create a mutable array of strings?
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 17 02:57:29 PDT 2015
On Sun, 17 May 2015 09:39:21 +0000
Dennis Ritchie via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> 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.
allready there:
auto s = ["foo", "bar"].map!"a.dup".array;
:)
More information about the Digitalmars-d-learn
mailing list