www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21582] New: ApplyLeft fails with some function templates

https://issues.dlang.org/show_bug.cgi?id=21582

          Issue ID: 21582
           Summary: ApplyLeft fails with some function templates
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: john.loughran.colvin gmail.com

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...)

--
Jan 25