digitalmars.D.learn - put string[] into a appender without loop?
- AsmMan (3/3) Sep 21 2014 I'd like to copy an array string into a appender!string() but I
- AsmMan (9/12) Sep 21 2014 call:
- Vladimir Panteleev (6/18) Sep 21 2014 put(app, s);
- AsmMan (6/30) Sep 21 2014 this give undefined identifier: 'put' error. (std.array is
- Vladimir Panteleev (6/10) Sep 21 2014 No, I was just thinking aloud about how Appender could be
- AsmMan (5/15) Sep 21 2014 Thanks, I was thinking std.array is enough
- H. S. Teoh via Digitalmars-d-learn (11/14) Sep 21 2014 Try this:
- monarch_dodra (6/21) Sep 22 2014 FYI, that's probably scary expensive in terms of
- ketmar via Digitalmars-d-learn (8/11) Sep 21 2014 On Sun, 21 Sep 2014 23:41:56 +0000
- ketmar via Digitalmars-d-learn (4/4) Sep 21 2014 On Mon, 22 Sep 2014 02:51:41 +0300
- kiran kumari (3/6) Sep 24 2014 see more example
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?
Sep 21 2014
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?
Sep 21 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: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.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?
Sep 21 2014
On Monday, 22 September 2014 at 00:09:22 UTC, Vladimir Panteleev wrote:On Sunday, 21 September 2014 at 23:48:59 UTC, AsmMan wrote:this give undefined identifier: 'put' error. (std.array is already included, buffer.put(string) doesn't give same error) The copy of an array doesn't happen often as string but do suggest to I want something else instead of appender?On Sunday, 21 September 2014 at 23:41:58 UTC, AsmMan wrote: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.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?
Sep 21 2014
On Monday, 22 September 2014 at 00:18:03 UTC, AsmMan wrote:this give undefined identifier: 'put' error. (std.array is already included, buffer.put(string) doesn't give same error)You need to import std.range.The copy of an array doesn't happen often as string but do suggest to I want something else instead of appender?No, I was just thinking aloud about how Appender could be improved in the future. To minimize allocations right now, you could write your own put-like function which calls Appender.reserve.
Sep 21 2014
On Monday, 22 September 2014 at 00:30:44 UTC, Vladimir Panteleev wrote:On Monday, 22 September 2014 at 00:18:03 UTC, AsmMan wrote:Thanks, I was thinking std.array is enoughthis give undefined identifier: 'put' error. (std.array is already included, buffer.put(string) doesn't give same error)You need to import std.range.this is not critical (for now, I'm not doing any optmization) but I'll save the idea.The copy of an array doesn't happen often as string but do suggest to I want something else instead of appender?No, I was just thinking aloud about how Appender could be improved in the future. To minimize allocations right now, you could write your own put-like function which calls Appender.reserve.
Sep 21 2014
On Sun, Sep 21, 2014 at 11:41:56PM +0000, AsmMan via Digitalmars-d-learn 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?Try this: import std.array : appender; import std.algorithm : joiner, copy; string[] arr = ["ab", "cd", "efg"]; auto app = appender!string(); arr.joiner.copy(app); assert(app.data == "abcdefg"); T -- One reason that few people are aware there are programs running the internet is that they never crash in any significant way: the free software underlying the internet is reliable to the point of invisibility. -- Glyn Moody, from the article "Giving it all away"
Sep 21 2014
On Sunday, 21 September 2014 at 23:50:50 UTC, H. S. Teoh via Digitalmars-d-learn wrote:On Sun, Sep 21, 2014 at 11:41:56PM +0000, AsmMan via Digitalmars-d-learn wrote:FYI, that's probably scary expensive in terms of encoding/decoding. Using the "free" std.range.put should take care of everything, natively.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?Try this: import std.array : appender; import std.algorithm : joiner, copy; string[] arr = ["ab", "cd", "efg"]; auto app = appender!string(); arr.joiner.copy(app); assert(app.data == "abcdefg"); T
Sep 22 2014
On Sun, 21 Sep 2014 23:41:56 +0000 AsmMan via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:I'd like to copy an array string into a appender!string() but I=20 can't see how to do this without loop myself over the string=20 array. Is there a native function or should I write it myself?hm... '.put' should work. i.e. string s =3D `something`; auto ap =3D appender!string(); ap.put(s); // now ap.data returns `something`
Sep 21 2014
On Mon, 22 Sep 2014 02:51:41 +0300 ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote: sorry, forgot that. i misunderstood your question.
Sep 21 2014
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?see more example http://techgurulab.com/course/java-quiz-online/
Sep 24 2014