switch using a variable that can cast to both integer and string
Peter Alexander
peter.alexander.au at gmail.com
Wed Sep 26 01:10:47 PDT 2012
On Wednesday, 26 September 2012 at 08:02:24 UTC, Jonathan M Davis
wrote:
> I would expect it to give errors on those case statements,
> because they're not
> actually ints or strings.
http://dlang.org/statement.html#SwitchStatement
"The case expressions must all evaluate to a constant value or
array, or a runtime initialized const or immutable variable of
integral type. They must be implicitly convertible to the type of
the switch Expression."
In the example, the case expression evaluate to a constant value,
and they are implicitly convertible via alias this.
More information about the Digitalmars-d
mailing list