UFCS for arguments other than first?

2016-11-11 Thread Heisenberg via Digitalmars-d
What would it take to implement the Uniform Function Call Syntax for a function's argument which is not the first? Right now it is possible to do the following: int someNumber(int a, int b) { return a + b; } void main() { int n1 = 5; int n2 = n1.someNumber(n1 + 1); // Here the `n1

Re: UFCS for arguments other than first?

2016-11-11 Thread John Colvin via Digitalmars-d
On Friday, 11 November 2016 at 16:39:26 UTC, Heisenberg wrote: What would it take to implement the Uniform Function Call Syntax for a function's argument which is not the first? Right now it is possible to do the following: int someNumber(int a, int b) { return a + b; } void main() {

Re: UFCS for arguments other than first?

2016-11-11 Thread Heisenberg via Digitalmars-d
On Friday, 11 November 2016 at 17:07:50 UTC, John Colvin wrote: I'm sure there are loads of corner cases this doesn't cover, but: template inPos(uint n, alias f) { auto inPos(Args...)(auto ref Args args) { return f(args[1 .. n+1], args[0], args[n+1 .. $]); } } import std.st

Re: UFCS for arguments other than first?

2016-11-11 Thread John Colvin via Digitalmars-d
On Friday, 11 November 2016 at 18:33:09 UTC, Heisenberg wrote: On Friday, 11 November 2016 at 17:07:50 UTC, John Colvin wrote: I'm sure there are loads of corner cases this doesn't cover, but: template inPos(uint n, alias f) { auto inPos(Args...)(auto ref Args args) { return f(

Re: UFCS for arguments other than first?

2016-11-11 Thread Heisenberg via Digitalmars-d
On Friday, 11 November 2016 at 21:51:29 UTC, John Colvin wrote: On Friday, 11 November 2016 at 18:33:09 UTC, Heisenberg wrote: On Friday, 11 November 2016 at 17:07:50 UTC, John Colvin wrote: I'm sure there are loads of corner cases this doesn't cover, but: template inPos(uint n, alias f) {

Re: UFCS for arguments other than first?

2016-11-11 Thread Jonathan M Davis via Digitalmars-d
On Friday, November 11, 2016 22:48:24 Heisenberg via Digitalmars-d wrote: > Isn't the whole point of UFCS implementation in providing better > re-usability and scalability, helping the encapsulation, making > the chaining of function calls easier? The primary benefit of UFCS is so that generic cod

Re: UFCS for arguments other than first?

2016-11-11 Thread Temtaime via Digitalmars-d
On Friday, 11 November 2016 at 16:39:26 UTC, Heisenberg wrote: What would it take to implement the Uniform Function Call Syntax for a function's argument which is not the first? Right now it is possible to do the following: int someNumber(int a, int b) { return a + b; } void main() {

Re: UFCS for arguments other than first?

2016-11-12 Thread Heisenberg via Digitalmars-d
On Saturday, 12 November 2016 at 06:42:24 UTC, Temtaime wrote: You are wrong. We can use n1 for the second parameter. int someNumber(int a, int b) { return a + b; } int main() { int n1 = 5; return (n1.someNumber = n1); // 10 } In this specific case, yes - however: int getR

Re: UFCS for arguments other than first?

2016-11-12 Thread Heisenberg via Digitalmars-d
On Friday, 11 November 2016 at 23:27:30 UTC, Jonathan M Davis wrote: Ultimately, the only technical benefit from UFCS is that it allows you to call a function without caring whether it's a member function or a free function, which is of great benefit to generic code and not really much else. Ot