Re: Building a string from n chars

2014-09-04 Thread Nordlöw
On Wednesday, 3 September 2014 at 20:46:40 UTC, monarch_dodra wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? s ~= repeat('*', n).array(); Should be enough. Why the to!string? You're correct. The .to!string was unnecessary.

Re: Building a string from n chars

2014-09-04 Thread Nordlöw
On Wednesday, 3 September 2014 at 20:20:09 UTC, Meta wrote: Does this work? s ~= *.replicate(n); Yes, thanks. So what's best? type ~= '*'.repeat(pointerCount).array; or type ~= *.replicate(pointerCount); ? Further, -vgc says only ~= will allocate: t_repeat_replicate.d(12,19):

Re: Building a string from n chars

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 19:22:42 UTC, Nordlöw wrote: Is DMD/Phobos already that clever!? Further -vgc has nothing to say about string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= *.replicate(n); .

Re: Building a string from n chars

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 19:24:00 UTC, Nordlöw wrote: string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= *.replicate(n); After having read http://dlang.org/phobos/std_array.html#.replicate I came to the conclusion that the lazy std.range:repeat is preferred. I'm still

Re: Building a string from n chars

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:38:39 UTC, Nordlöw wrote: On Thursday, 4 September 2014 at 19:24:00 UTC, Nordlöw wrote: string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= *.replicate(n); After having read http://dlang.org/phobos/std_array.html#.replicate I came to the

Re: Building a string from n chars

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:57:43 UTC, monarch_dodra wrote: On Thursday, 4 September 2014 at 20:38:39 UTC, Nordlöw wrote: On Thursday, 4 September 2014 at 19:24:00 UTC, Nordlöw wrote: string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= *.replicate(n); After having read

Re: Building a string from n chars

2014-09-03 Thread Meta via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 19:43:26 UTC, Nordlöw wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? Does this work? s ~= *.replicate(n);

Re: Building a string from n chars

2014-09-03 Thread Meta via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 20:20:09 UTC, Meta wrote: On Wednesday, 3 September 2014 at 19:43:26 UTC, Nordlöw wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? Does this work? s ~= *.replicate(n); Sorry, I should qualify

Re: Building a string from n chars

2014-09-03 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 19:43:26 UTC, Nordlöw wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? s ~= repeat('*', n).array(); Should be enough. Why the to!string? There's 1 useless allocation, but I think that's OK for code

Re: Building a string from n chars

2014-09-03 Thread Cassio Butrico via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 20:46:40 UTC, monarch_dodra wrote: On Wednesday, 3 September 2014 at 19:43:26 UTC, Nordlöw wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? s ~= repeat('*', n).array(); Should be enough. Why the