Named parameters

Martin Nowak via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 25 07:05:32 PDT 2015


On Saturday, 25 July 2015 at 13:52:09 UTC, Andrei Alexandrescu 
wrote:
>> For one thing, it avoids the ugly hack which is the Flag 
>> template and
>> Yes/No structs.
>>
>> With Flag:
>>

The idiom goes like this.

/// Flag to control whether or not to keep line endings
alias KeepTerminator = Flag!"KeepTerminator";
///
string getLine(KeepTerminator KeepTerminator);

usage:

getLine(KeepTerminator.yes);
or
getLine(Yes.keepTerminator);

So named Boolean flags are a solved problem and are a good 
improvement over getLine(true) IMO.


More information about the Digitalmars-d mailing list