Error with implicit cast of ^^=

wjoe invalid at example.com
Wed Jul 14 09:44:42 UTC 2021


On Tuesday, 13 July 2021 at 15:14:26 UTC, Ali Çehreli wrote:
> 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

I was planning on adding support for over-/underflow bits but 
this is much better. Thanks!


More information about the Digitalmars-d-learn mailing list