R With(I, R)(I o, R function (I) fun)
{
static if(isAssignable!(I, typeof(null)))
return o is null ? null : fun(o);
else
return fun(o);
}
class Person
{
private
{
string _name;
Address _address;
}
@property
{
string name() { return _name; }
void name(string v) { _name = v; }
Address address() { return _address; }
void address(Address v) { _address = v; }
}
}
in main function
----------------
foreach(p; persons)
p.With((Person x) => x.address); // works
but
----------------
foreach(p; persons)
p.With(x => x.address); // error
nullcheck.d(89): Error: template maybe.With does not match any
function template
declaration. Candidates are:
maybe.d(20): maybe.With(I, R)(I o, R function(I) fun)
nullcheck.d(89): Error: template maybe.With(I, R)(I o, R
function(I) fun) cannot
deduce template function from argument types !()(Person,void)
Why?