Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Steven Schveighoffer
On Tue, 25 Mar 2014 19:13:07 -0400, H. S. Teoh wrote: On Tue, Mar 25, 2014 at 10:02:33PM +, monarch_dodra wrote: On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote: >Is there a performance benefit? Is it simply because it's more general? [...] There is *1* thing you should

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread H. S. Teoh
On Tue, Mar 25, 2014 at 10:02:33PM +, monarch_dodra wrote: > On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote: > >Is there a performance benefit? Is it simply because it's more general? [...] > There is *1* thing you should take into account though: "to!" is a > no-op for string=>

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Mark Isaacson
Much appreciated everyone! I had a vague intuition that these were the reasons, but it was helpful to spell them out. I'm especially partial to the self-documentation reasoning.

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread monarch_dodra
On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote: Is there a performance benefit? Is it simply because it's more general? Mostly because it's more generic. For example: If instead you want to do "string" => "char[]", then your code will have to be changed to use "dup". if instead

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread bearophile
Mark Isaacson: why use `to!string` instead of just doing `line[2 .. $].idup`? I sometimes prefer the text function: = line[2 .. $].text; Bye, bearophile

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Justin Whear
On Tue, 25 Mar 2014 21:35:46 +, Mark Isaacson wrote: > I am presently working my way through TDPL for the second time, and > there's an example in chapter 1 to the effect of: > > [code] > string currentParagraph; > foreach(line; stdin.byLine()) { >if (line.length > 2) { > currentPara

[Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Mark Isaacson
I am presently working my way through TDPL for the second time, and there's an example in chapter 1 to the effect of: [code] string currentParagraph; foreach(line; stdin.byLine()) { if (line.length > 2) { currentParagraph = to!string(line[2 .. $]); } } [/code] The explicit conversion