Use case for std.bind
Lars Kyllingstad
public at kyllingen.NOSPAMnet
Tue Feb 24 05:49:06 PST 2009
Daniel Keep wrote:
>
> Lars Kyllingstad wrote:
>> [snip]
>>
>> I for one like it, and would very much like to see such a syntax in D2.
>> Also, I'd have it work with either of a function's arguments, not only
>> the leading or trailing ones:
>>
>> int foo(int a, int b, int c, int d) {...}
>> auto bar1 = foo(_, b, c, d);
>> auto bar2 = foo(a, b, c, _);
>> auto bar3 = foo(_, b, _, d);
>>
>> assert (is (typeof(bar3) == int delegate(int, int)));
>>
>> In its simplest form, it would just be syntactic sugar for the delegate
>> literal. But I'm curious: If foo is a pure function, couldn't the
>> compiler perform some extra optimization here?
>>
>> -Lars
>
> auto a = b(_, c(_, x), _);
>
> What are the types of a, b and c? What if b has multiple overloads or
> is templated?
>
> Context-dependant grammar (let alone context-dependant single character
> symbols): just say "no".
>
> -- Daniel
Good point. How about this alternative syntax, then:
auto bar3 = foo(int, b, int, d);
Will this also cause problems?
-Lars
More information about the Digitalmars-d
mailing list