Cannot implicitly convert expression `true` of type `bool` to `Flag`
Ali Çehreli
acehreli at yahoo.com
Thu Oct 15 23:43:03 UTC 2020
On 10/15/20 4:25 PM, Paul Backus wrote:
> On Thursday, 15 October 2020 at 21:33:32 UTC, Ali Çehreli wrote:
>> bool someFlag;
>> // ...
>> foo(someFlag ? Yes.someFlag : No.someFlag);
>
> An easier way is to use a cast:
>
> bool someFlag;
> // ...
> foo(cast(Flag!"someFlag") someFlag);
>
> std.conv.to also knows how to handle this conversion:
>
> foo(someFlag.to!(Flag!"someFlag"));
I still like the ternary operator more partly because it uses features
that are explained in the documentation. :) Both of your methods rely on
the fact that the implementation is a bool-based enum. Are the users
expected to know that? If yes, then the library can't change the
implementation.
Ali
More information about the Digitalmars-d
mailing list