On 04/10/2011 04:10 PM, spir wrote:
Hello,

I need a trick to allow a function template parameter be optional.
The following (reduced case) fails because D wants to call f:

uint f(uint i) { return i; }
struct S (alias func=null) {
enum bool hasFunc = !(func == null); // *** error line ***
}
unittest {
// ok
auto s1 = S!()();
writeln(s1.hasFunc);
// not ok
auto s2 = S!(f)();
writeln(s2.hasFunc);
}
==>
Error: function ___.f (uint i) is not callable using argument types ()
(I consider that a bug due to "f" implicitely meaning "f()" --but this is
another story.)

The following also fails:

// not ok
auto s3 = S1!(&f)();
writeln(s3.hasFunc);
==>
Error: expression & f is not a valid template value argument

PS: I also cannot pass a typed func:

struct S (uint delegate (uint) func=null) {
    enum bool hasFunc = !(func == null);
}

==>
Error: arithmetic/string type expected for value-parameter, not uint delegate(uint)

--
_________________
vita es estrany
spir.wikidot.com

Reply via email to