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
Is there a way to do this via ^^= ?
This is part of a unittest for opIndexOpAssign where the type of x is that of i.opIndex(_i). It's generated from a list of operators like this:
part_int_t!(1, 8, 10) i;
static assert(is(typeof(i[0]): short));
static assert(is(typeof(i[1]): byte));
static assert(is(typeof(i[2]): bool));
static foreach(op; ["+=", "-=", "^^=", ...])
{{
typeof(i[1]) x;
mixin("x" ~ op ~ "y;");
mixin("i[1]" ~ op ~ "y;");
assert(i == x);
}}
I rewrote it to something like
mixin("x = cast(typeof(x))(x" ~ op[0..$-1] ~ " y);");
but I'm curious if there's a less convoluted way.