digitalmars.D.learn - "optional" func alias template param
- spir (30/30) Apr 10 2011 Hello,
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 Denis -- _________________ vita es estrany spir.wikidot.com
Apr 10 2011