On 6/11/11 2:12 PM, Robert Clipsham wrote:
On 11/06/2011 12:54, Andrei Alexandrescu wrote:
Consider two statements:

1. "I dislike Flag. It looks ugly to me."

This statement holds true for me.

2. "I dislike Flag. Instead I want named arguments."

This one is perhaps true. I've never needed named arguments.

There is little retort to (1) - it simply counts as a vote against. For
(2) the course of action is to point out the liabilities of changing the
language.

Andrei

So I had an idea.

----
struct Flag
{
static bool opDispatch(string n)()
{
static if (n[0..2] == "no")
{
return false;
}
else
{
return true;
}
}
}

void myFunc(bool foo, bool bar)
{
}

void main()
{
myFunc(Flag.foo, Flag.noBar);
}
----

* 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

Reply via email to