default opAssign(string) behaviour
Steven Schveighoffer
schveiguy at yahoo.com
Thu Jan 28 03:53:26 PST 2010
On Wed, 27 Jan 2010 20:32:20 -0500, strtr <strtr at spam.com> wrote:
> Personally, I use (D1)std2.conv a lot to get values from strings and
> thus would love the following default behaviour for all types:
>
> int i = "0"; // i = 0
Um... why? How is int i = 0; more difficult to use/understand than int i
= "0";
If you want to assign from a variable, then i = to!(int)x; works. It's
not that hard to do.
The issue with the compiler trying to understand what you are doing
results in ambiguities in other places. What does this mean?
int i = "1" + "2"; // i == 3 or 12?
These kinds of things are avoided, all by having a simple requirement that
you use the to!() function.
> i = cast( int ) "0"; // i = 48 ( If I read the utf8 table correctly )
i = '0';
or
i = cast(int) '0';
works. Not sure of the first, but the second definitely.
-Steve
More information about the Digitalmars-d-learn
mailing list