1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import std.stdio; struct carry(TResult, TParams...) { public this(TResult delegate(TParams) _f) { f = _f; } public auto opCall(TParams[0] para) { static if (TParams.length > 1) { return carry!(TResult, TParams[1 .. $])( (TParams[1 .. $] args) { return f(para, args); } ); } else { return f(para); } } public TResult delegate(TParams) f; } void main() { auto f = carry!(int, int, int, int, int)( (int a, int b, int c, int d) { return a+b+c+d; } ); writeln(f(1)(2)(3)(4)); } |
aW1wb3J0IHN0ZC5zdGRpbzsKCnN0cnVjdCBjYXJyeShUUmVzdWx0LCBUUGFyYW1zLi4uKSB7CglwdWJsaWMgdGhpcyhUUmVzdWx0IGRlbGVnYXRlKFRQYXJhbXMpIF9mKSB7CgkJZiA9IF9mOwoJfQoJcHVibGljIGF1dG8gb3BDYWxsKFRQYXJhbXNbMF0gcGFyYSkgewoJCXN0YXRpYyBpZiAoVFBhcmFtcy5sZW5ndGggPiAxKSB7CgkJCXJldHVybiBjYXJyeSEoVFJlc3VsdCwgVFBhcmFtc1sxIC4uICRdKSggKFRQYXJhbXNbMSAuLiAkXSBhcmdzKSB7IHJldHVybiBmKHBhcmEsIGFyZ3MpOyB9ICk7CgkJfSBlbHNlIHsKCQkJcmV0dXJuIGYocGFyYSk7CgkJfQoJfSAKCXB1YmxpYyBUUmVzdWx0IGRlbGVnYXRlKFRQYXJhbXMpIGY7Cn0KCnZvaWQgbWFpbigpIHsKCWF1dG8gZiA9IGNhcnJ5IShpbnQsIGludCwgaW50LCBpbnQsIGludCkoIChpbnQgYSwgaW50IGIsIGludCBjLCBpbnQgZCkgeyByZXR1cm4gYStiK2MrZDsgfSApOwoJd3JpdGVsbihmKDEpKDIpKDMpKDQpKTsKfQ==
prog.d(19): Error: constructor prog.carry!(int,int,int,int,int).carry.this (int delegate((int, int _param_0, int _param_1, int _param_2)) _f) is not callable using argument types (int) prog.d(19): Error: cannot implicitly convert expression (1) of type int to int delegate((int, int _param_0, int _param_1, int _param_2)) prog.d(19): Error: cannot cast int to int delegate((int, int _param_0, int _param_1, int _param_2)) prog.d(19): Error: constructor prog.carry!(int,int,int,int,int).carry.this (int delegate((int, int _param_0, int _param_1, int _param_2)) _f) is not callable using argument types (int) prog.d(19): Error: cannot implicitly convert expression (2) of type int to int delegate((int, int _param_0, int _param_1, int _param_2)) prog.d(19): Error: cannot cast int to int delegate((int, int _param_0, int _param_1, int _param_2)) prog.d(19): Error: constructor prog.carry!(int,int,int,int,int).carry.this (int delegate((int, int _param_0, int _param_1, int _param_2)) _f) is not callable using argument types (int) prog.d(19): Error: cannot implicitly convert expression (3) of type int to int delegate((int, int _param_0, int _param_1, int _param_2)) prog.d(19): Error: cannot cast int to int delegate((int, int _param_0, int _param_1, int _param_2)) prog.d(19): Error: constructor prog.carry!(int,int,int,int,int).carry.this (int delegate((int, int _param_0, int _param_1, int _param_2)) _f) is not callable using argument types (int) prog.d(19): Error: cannot implicitly convert expression (4) of type int to int delegate((int, int _param_0, int _param_1, int _param_2)) prog.d(19): Error: cannot cast int to int delegate((int, int _param_0, int _param_1, int _param_2))
-
result: Compilation error (maybe you wish to see an example for D (dmd))


