Proposal request: explicit propreties
Steven Schveighoffer
schveiguy at yahoo.com
Tue Apr 1 11:53:33 PDT 2008
"Bill Baxter" wrote
> I've also run across cases where the compiler fails to realize it should
> call a property method unless you explicitly put the () after it. I can't
> recall exactly where. That's just a bug, but it is something to consider.
It's when the object being returned by a property overloads opCall. The
prime example I know is tango's Stdout.newline():
Stdout("hello").newline()("world").newline;
If you don't include the extra (), then the compiler thinks you're calling
newline("world");
This is one case where the nature of D properties is exploited in a way that
would be unnatural with explicit properties. newline is clearly not a
property, but using it in this way is pretty clear (and convenient).
-Steve
More information about the Digitalmars-d
mailing list