[Style] Converting from char[] to string, to!string vs idup
monarch_dodra
monarchdodra at gmail.com
Tue Mar 25 15:02:33 PDT 2014
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 you want to do char[] => dstring, then your code will
simply not work at all.
By contrast, "to!" will "just work". It's "A one-stop shop for
converting values from one type to another."
There is *1* thing you should take into account though: "to!" is
a no-op for string=>string or char[]=>char[], or anything else
that can be implicitly converted as such. In contrast,
"dup"/"idup" will create an actual copy.
Not that this is good or bad. Just something you should keep in
mind.
More information about the Digitalmars-d-learn
mailing list