Why is Phobos `Flag` so overthought ?
    cc 
    cc at nevernet.com
       
    Wed May  8 04:27:13 UTC 2024
    
    
  
On Monday, 6 May 2024 at 17:55:49 UTC, user1234 wrote:
> I think this just works:
>
> ```d
> enum Flag : bool
> {
>     no,
>     yes
> }
> ```
> ...
> must be a reason but I cant find it RN ;)
In "properly" designed Phobos packages, it's unambiguous.  Take 
for example std.datetime.stopwatch:
```d
import std.typecons : Flag;
alias AutoStart = Flag!"autoStart";
alias MyOtherFlag = Flag!"myOtherFlag";
...
//auto sw = StopWatch(true); // Not allowed
//auto sw = StopWatch(MyOtherFlag.yes); // Not allowed
auto sw = StopWatch(AutoStart.yes);
```
It doesn't allow a simple boolean to be used as an argument, or 
any other Flag as they are different instantiations of a template 
rather than equivalent aliases.
It is however awful, cumbersome, annoying design and needs to be 
completely phased out now that we have named arguments.
    
    
More information about the Digitalmars-d-learn
mailing list