Why is Phobos `Flag` so overthought ?
user1234
user1234 at 12.de
Mon May 6 18:12:57 UTC 2024
On Monday, 6 May 2024 at 18:06:53 UTC, Julian Fondren wrote:
> On Monday, 6 May 2024 at 17:55:49 UTC, user1234 wrote:
>> I think this just works:
>>
>> ```d
>> enum Flag : bool
>> {
>> no,
>> yes
>> }
>>
>> alias AllowVancancy = Flag; // example usage
>> ```
>
> ```d
> import std.stdio : writeln;
>
> enum Flag : bool { no, yes }
> alias Traditional = Flag;
> alias Color = Flag;
>
> void hello(Traditional traditional, Color color) {
> if (traditional && color) {
> writeln("\x1b[31;1mhello world\x1b[0m");
> } else if (traditional && !color) {
> writeln("hello world");
> } else if (!traditional && color) {
> writeln("\x1b[31;1mHello, world!\x1b[0m");
> } else {
> writeln("Hello, world!");
> }
> }
>
> void main() {
> hello(Color.yes, Traditional.yes); // this is wrong, but
> accepted
> }
> ```
Ah yes I see, strongly typed bools.
Thanks 👍.
More information about the Digitalmars-d-learn
mailing list