Comment #0 by john.loughran.colvin — 2021-01-25T19:34:20Z
import std.meta : ApplyLeft;
alias orIfNull = ApplyLeft!(orIf, x => x is null);
auto ref orIf(alias test, T0, T1)(auto ref T0 v, auto ref T1 def) {
return test(v) ? def : v;
}
alias orIfNull2 = ApplyLeft!(orIf2, x => x is null);
template orIf2(alias test) {
auto ref orIf2(T0, T1)(auto ref T0 v, auto ref T1 def) {
return test(v) ? def : v;
}
}
auto foo() {
string s;
auto a = s.orIfNull(""); // fails in std.meta
auto b = s.orIfNull2(""); // ok
}
full error:
/dlang/dmd/linux/bin64/../../src/phobos/std/meta.d(1297): Error: template instance Template!((x) => x is null) does not match template declaration orIf(alias test, T0, T1)(auto ref T0 v, auto ref T1 def)
onlineapp.d(19): Error: template instance onlineapp.ApplyLeft!() error instantiating
onlineapp.d(19): Error: template onlineapp.ApplyLeft!(orIf, (x) => x is null).ApplyLeft cannot deduce function from argument types !()(string, string), candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/meta.d(1297): ApplyLeft(right...)
Comment #1 by robert.schadek — 2024-12-01T16:38:17Z