Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 06, 2020 Algebraic and implicit conversions | ||||
---|---|---|---|---|
| ||||
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`? |
January 06, 2020 Re: Algebraic and implicit conversions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | 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;
|
January 06, 2020 Re: Algebraic and implicit conversions | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | On 1/6/20 2:33 PM, drug wrote:
> 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;
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.
-Steve
|
January 06, 2020 Re: Algebraic and implicit conversions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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.
|
Copyright © 1999-2021 by the D Language Foundation