Why is Phobos `Flag` so overthought ?
    Dukc 
    ajieskola at gmail.com
       
    Wed May  8 11:02:20 UTC 2024
    
    
  
Nick Treleaven kirjoitti 8.5.2024 klo 13.24:
> On Wednesday, 8 May 2024 at 04:27:13 UTC, cc wrote:
>> 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.
> 
> Flag enforces that the argument says what it relates to. `true` does not 
> say what it relates to. Named arguments are optional, so I don't see how 
> they could make Flag redundant.
Well,
```D
private struct Undefinable{}
auto functionTakingFlags
(   int normalArg,
     Undefinable = Undefinable.init,
     bool Flag1,
     Undefinable = Undefinable.init,
     bool Flag2
){  // fun body...
}
```
As I understand it, this forces the client to use named arguments 
because they would be trying to pass an `Undefinable` otherwise. They 
probably could pass `Undefinable` if they really wanted and therefore 
avoid using named args but they wouldn't do that accidentally.
Whether that is any better than the library `Flag` type is up to taste.
    
    
More information about the Digitalmars-d-learn
mailing list