Partial application of compile time args type deduction

QAston via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 20 01:48:40 PST 2016


On Wednesday, 20 January 2016 at 00:50:49 UTC, Ali Çehreli wrote:
> On 01/19/2016 04:22 PM, QAston wrote:
>> [...]
>
> Is this it? If so, is it already in std.functional? (I could 
> not find it. :) )
>
> auto appendMapped(alias f, R, T)(R r, T elem) {
>     r ~= f(elem);
>     return r;
> }
>
> int minus(int i) {
>     return -i;
> }
>
> unittest {
>     int[] ar;
>
>     template bindFirstParam(alias original, alias func, 
> Args...) {
>         auto bindFirstParam(Args...)(Args args) {
>             return original!(func, Args)(args);
>         }
>     }
>
>     alias appendMinus = bindFirstParam!(appendMapped, minus);
>
>     assert (appendMinus!(int[], int)(ar, 10) == [-10]); // 
> compiles
>     assert (appendMinus(ar, 10) == [-10]); // doesn't compile
> }
>
> void main() {
> }
>
> Ali

Works, thanks!



More information about the Digitalmars-d-learn mailing list