According to the docs, std.conv.to uses cast operator under the
hood, and since the following works:
enum MyEnumType {a}
auto val = cast(MyEnumType) 42;
...it seems natural that to!MyEnumType(42) should work as well.
But currently it gives error:
template instance std.conv.to!(MyEnumType).to!(
On Monday, 16 July 2012 at 17:35:33 UTC, Tommi wrote:
According to the docs, std.conv.to uses cast operator under the
hood, and since the following works:
enum MyEnumType {a}
auto val = cast(MyEnumType) 42;
...it seems natural that to!MyEnumType(42) should work as well.
But currently it gives
On Monday, 16 July 2012 at 20:22:12 UTC, Era Scarecrow wrote:
You can convert a enum to an int, but not the other way around.
[...]
MyEnumType z = cast(MyEnumType) 100; //Error: an int is not an
enum! (Even if it's a valid match)
I do this all the time
enum E
{
A = 100,
B = 200
}
E
On Monday, 16 July 2012 at 21:00:00 UTC, cal wrote:
On Monday, 16 July 2012 at 20:22:12 UTC, Era Scarecrow wrote:
You can convert a enum to an int, but not the other way around.
[...]
MyEnumType z = cast(MyEnumType) 100; //Error: an int is not an
enum! (Even if it's a valid match)
I do this
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
On Monday, 16 July 2012 at 21:59:17 UTC, Tommi wrote:
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.
I had the impression it was illegal by the compiler; Logicall
"Era Scarecrow" , dans le message (digitalmars.D:172568), a écrit :
> On Monday, 16 July 2012 at 21:59:17 UTC, Tommi wrote:
>> 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