Error with implicit cast of ^^=
Ali Çehreli
acehreli at yahoo.com
Tue Jul 13 15:14:26 UTC 2021
On 7/13/21 4:12 AM, wjoe wrote:
> ```D
> byte x = some_val;
> long y = some_val;
>
> x ^^= y; // Error: cannot implicitly convert expression
> pow(cast(long)cast(int)x, y) of type long to byte
[...]
> I rewrote it to something like
> ```D
> mixin("x = cast(typeof(x))(x" ~ op[0..$-1] ~ " y);");
> ```
> but I'm curious if there's a less convoluted way.
If it's important, std.conv.to checks the value:
import std.conv;
void main() {
byte x = 2;
long y = 6;
x = (x ^^ y).to!(typeof(x));
}
For example, run-time error if y == 7.
Ali
More information about the Digitalmars-d-learn
mailing list