Bug 1101 – Can't not deduce template correctly

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-04-06T01:02:00Z
Last change time
2014-02-16T15:23:06Z
Assigned to
bugzilla
Creator
davidl

Comments

Comment #0 by davidl — 2007-04-06T01:02:11Z
the following is not compilable: enum type{ a, b, } template XX(uint a, uint c) { uint XX(){ return (a*256+c);} } void main() { int k=XX(cast(uint)type.a,cast(uint)type.b); // can't match any template declaration while it should } but a workaround as following is working fine : enum type{ a, b, } template XX(uint a, uint c) { uint XX(){ return (a*256+c);} } void main() { int k=XX!(cast(uint)type.a,cast(uint)type.b)(); }
Comment #1 by thomas-dloop — 2007-04-06T04:14:43Z
# template X(uint a, uint c){ # uint X(){ return 0; } # } # # X(1u,2u); According to http://www.digitalmars.com/d/template.html this doesn't the above code doesn't seem to be legal. The following code however is legal and compiles: # template X(T1, T2){ # uint X(T1 a, T2 b){ return 0; } # } # # X(1u,2u); and # template X(T){ # uint X(T a, T b){ return 0; } # } # # X(1u,2u);
Comment #2 by davidl — 2007-04-09T04:10:47Z
can u show me exact sentence in the doc prevent the template i use? The problem is dmd prevent IFTI from compiling while it allows the EXPLICITL template form. the uint a, uint c here are just some compile time literal integer
Comment #3 by fvbommel — 2007-04-09T05:24:14Z
How about: ===== Function templates can be explicitly instantiated [snip] or implicitly, where the TemplateArgumentList is deduced from the types of the function arguments ===== Note: The *types* of the function arguments, not their values. IFTI only works for type arguments. This code is pretty close to yours though: ----- enum type{ a, b, } template XX(uint a, uint c) { uint XX(){ return (a*256+c);} } void main() { int k=XX!(type.a,type.b); } ----- All in all, a one-character edit is all it took. (The casts are redundant so I removed them, and the trailing parentheses in your "workaround" are optional because of property syntax. Both should be fine if you left them in though) If you still don't understand what's wrong with your code after reading this, I suggest you post in digitalmars.D.learn instead of reopening this issue.
Comment #4 by davidl — 2007-04-09T10:58:34Z
umm, i get it. It's as designed , making IFTI deduce TemplateArgumentList in the way which i thought it were would cause confliction between template(t:uint) and template(uint a)