Flag proposal
Robert Clipsham
robert at octarineparrot.com
Sat Jun 11 13:31:00 PDT 2011
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);
--
Robert
http://octarineparrot.com/
More information about the Digitalmars-d
mailing list