UFCS for arguments other than first?
Heisenberg via Digitalmars-d
digitalmars-d at puremagic.com
Fri Nov 11 14:48:24 PST 2016
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)
>>> {
>>> auto inPos(Args...)(auto ref Args args)
>>> {
>>> return f(args[1 .. n+1], args[0], args[n+1 .. $]);
>>> }
>>> }
>>>
>>> import std.stdio;
>>> alias formatSecond = inPos!(1, writefln);
>>>
>>> void main()
>>> {
>>>
>>> 1.writeln(2,3,4,5);
>>> 1.inPos!(2, writeln)(2,3,4,5);
>>>
>>> 42.formatSecond("The answer is %d");
>>> }
>>>
>>> and of course you could easily develop more powerful
>>> templates that could do any other order manipulations you
>>> like.
>>
>> That might be a solution as well. Specifying the position near
>> the variable will make the code much more straightforward to
>> read though, while not forcing the programmer to declare
>> separate templates in order to specify the position of a
>> function's argument..
>
> Not sure if either of those reasons are language-change worthy.
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?
-
http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394
-
https://forum.dlang.org/reply/ldlgoxuivwinqimtatqq@forum.dlang.org
More information about the Digitalmars-d
mailing list