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
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=>
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.
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
Mark Isaacson:
why use `to!string` instead of just doing `line[2 .. $].idup`?
I sometimes prefer the text function:
= line[2 .. $].text;
Bye,
bearophile
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
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