Flag proposal

Robert Clipsham robert at octarineparrot.com
Sat Jun 11 13:34:56 PDT 2011


On 11/06/2011 21:31, Robert Clipsham wrote:
> On 11/06/2011 20:59, Andrei Alexandrescu wrote:
>> On 6/11/11 2:12 PM, Robert Clipsham wrote:
>>> ....
>>> * No ugly templates
>>> * Self documenting
>>> * No overhead (dmd can inline it to myFunc(true, false))
>>> * Caller decides if they want it
>>
>> // Generate document in nook format
>> generatePdf("doc.pdf", Flag.nook);
>>
>>
>> Andrei
>>
>
> I'd call this a documentation issue. It's obvious you're passing true to
> the function. Of course, if you want to mitigate this somewhat,
> something like this could work:
>
> struct FuncFlag(alias func)
> {
> // See code from above, but use typeof(&func).stringof to get
> // a list of parameter names and make sure the passed name is valid
> // of course, you can't check position, but the only way to get
> // around that is named parameters or some sort of compiler support
> }
>
> alias FuncFlag!generatePdf PdfFlag;
>
> // This now fails to compile
> generatePdf("doc.pdf", PdfFlag.nook);
>

<idea>
You can actually check the order! Add in a counter to FuncFlag, and each 
time opDispatch is called increment it. You can use this to check the 
position. The obvious downside is optional parameters, where the counter 
will be incorrect unless you reset it.
</idea>

-- 
Robert
http://octarineparrot.com/


More information about the Digitalmars-d mailing list