put string[] into a appender without loop?
Vladimir Panteleev via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Sep 21 17:09:20 PDT 2014
On Sunday, 21 September 2014 at 23:48:59 UTC, AsmMan wrote:
> On Sunday, 21 September 2014 at 23:41:58 UTC, AsmMan wrote:
>> I'd like to copy an array string into a appender!string() but
>> I can't see how to do this without loop myself over the string
>> array. Is there a native function or should I write it myself?
>
> call:
>
> auto app = appender!string();
> string[] s = ["foo", "baa"];
> app.put(s);
>
> give a:
>
> \src\phobos\std\conv.d(9,9): Error: static assert
> "immutable(char) cannot be emplaced from a string." (b)
>
> How do I fix it?
put(app, s);
This is not an ideal solution, since Appender may reallocate
several times when appending the array items. Ideally, appender
itself should take a range of strings, so that it can preallocate
memory for them only once.
More information about the Digitalmars-d-learn
mailing list