-> and :: operators

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 9 03:15:41 PDT 2015


On Friday, 9 October 2015 at 10:03:18 UTC, ixid wrote:
> Too late to change but wouldn't it be better to have one 
> operator for members and another for UFCS? '->' would be good 
> for UFCS.

That would defeat the purpose of _Uniform_ Function Call Syntax. 
The whole point is that it uses the same syntax for member 
functions and free functions. In many cases, it's just for 
aesthetic purposes, but with templated code, it can be critical, 
because it allows you to effectively overload a free function 
with a member function (e.g. a particular range type could 
overload find if it had a more efficient implementation for it 
than the one in std.algorithm). It also makes it so that a type 
which doesn't have member functions can work in a template that's 
expecting the type to have specific member functions (e.g. arrays 
use free functions for the range primitives, but they're normally 
used as if they were member functions).

- Jonathan M Davis


More information about the Digitalmars-d mailing list