Why doesn't to!MyEnumType(42) work
tommitissari at hotmail.com
Mon Jul 16 14:59:16 PDT 2012
On Monday, 16 July 2012 at 20:22:12 UTC, Era Scarecrow wrote:
> MyEnumType y = cast(MyEnumType) 42; //Error: wtf is 42 anyways?
Like the previous fellow said, it's not an error.
To me that line of code says: "let's assign to MyEnumType
variable y some value that's not valid (as type MyEnumType
defines the word valid)". I think it's very useful to be able to
assign values which are unambiguously invalid, like NaN to float,
0xFF to char or some undefined value to enum. Sadly, with
integral types there's no such value that could be seen as
And to reiterate my point:
If the call:
...is supposed to be (and this I gather from the docs) under the
hood the same as:
...which works, then, logically, to!MyEnum(42) should also work.
More information about the Digitalmars-d