Regarding the proposed Binray Literals Deprecation

Loara loara at noreply.com
Sun Sep 18 11:00:12 UTC 2022


On Saturday, 17 September 2022 at 19:38:52 UTC, 0xEAB wrote:
> I fail to see the value of such a flag. If there were no plan 
> to remove or deprecate them, why issue a warning in the first 
> place?!
>
> There’s nothing wrong with binary literals (as in potential 
> pitfalls), isnt’t there?

Because it seems that some people really needs binary literals 
and can't work without them although there are many higher level 
alternatives.

Binary literals aren't efficient (too many digit to represent 
relatively small numbers) and aren't essential to the language 
itself (hex literals are far more efficient). If you need to set 
flags an enum approach makes code much more readable:

```d
enum MyFlag {A = 0, B, C}

T asFlag(T)(in T f) pure @safe nothrow @nogc{
   return (1 << f);
}

...

int field = MyFlag.A.asFlag & MyFlag.B.asFlag;
```




More information about the Digitalmars-d mailing list