digitalmars.D - UFCS - why only allow the first parameter?
- dennis luehring (8/8) Feb 22 2013 func(a,b,c)
- Jonathan M Davis (11/26) Feb 22 2013 Because that's not what member functions look like. The whole point is t...
- Timon Gehr (11/19) Feb 23 2013 Syntactically, because that is the comma operator.
func(a,b,c) can be written as a.func(b,c) is there a good reason for not allwing (a,b).func(c) or even (a,b,c).func()? for me it feels natural
Feb 22 2013
On Saturday, February 23, 2013 08:26:57 dennis luehring wrote:func(a,b,c) can be written as a.func(b,c) is there a good reason for not allwing (a,b).func(c) or even (a,b,c).func()? for me it feels naturalBecause that's not what member functions look like. The whole point is to make calling the free function look as if it were a member function on the type of its first argument. In general, it shouldn't matter whether a function is a free function or a member function, it can be called the same way. That then makes the call syntax for functions "universal." What you seem to be suggesting is to basically make it so that you can put the parens of the function call on either side of the function name, and that's not at all what UFCS is trying to do, and it doesn't help one whit with generic code, which is the primary benefit of UFCS. - Jonathan M Davis
Feb 22 2013
On 02/23/2013 08:26 AM, dennis luehring wrote:func(a,b,c) can be written as a.func(b,c) is there a good reason for not allwing (a,b).func(c) or even (a,b,c).func()? for me it feels naturalSyntactically, because that is the comma operator. The following shows an arbitrary limitation: auto seq(T...)(T args){ return args; } void func(int a,int b,int c){ } void main(){ seq(1,2).func(3); } But the following works: struct Q(T...){ T q; } auto q(T...)(T q){ return Q!T(q); } void func(int a,int b,int c){ } void main(){ q(1,2).q.func(3); }
Feb 23 2013