digitalmars.D.learn - Algebraic and implicit conversions
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (5/5) Jan 06 2020 Is there a reason why
- drug (5/8) Jan 06 2020 That's because you try to assign int, not long. This works:
- Steven Schveighoffer (7/17) Jan 06 2020 I think his question is, why shouldn't this work? e.g., this works:
- drug (2/5) Jan 06 2020 Ah, indeed. Sorry for noise.
Is there a reason why alias A = Algebraic!(long, string); A x; x = 42; doesn't implicitly convert `42` to `long` and stores it in `x`?
Jan 06 2020
06.01.2020 20:08, Per Nordlöw пишет:alias A = Algebraic!(long, string); A x; x = 42;That's because you try to assign int, not long. This works: alias A = Algebraic!(long, string); A x; x = 42L;
Jan 06 2020
On 1/6/20 2:33 PM, drug wrote:06.01.2020 20:08, Per Nordlöw пишет:I think his question is, why shouldn't this work? e.g., this works: long x; x = 42; FWIW, 3rd-party algebraic types (e.g. TaggedAlgebraic) will do a conversion for this. -Stevealias A = Algebraic!(long, string); A x; x = 42;That's because you try to assign int, not long. This works: alias A = Algebraic!(long, string); A x; x = 42L;
Jan 06 2020
06.01.2020 22:48, Steven Schveighoffer пишет:I think his question is, why shouldn't this work? e.g., this works:Ah, indeed. Sorry for noise.
Jan 06 2020