Thread overview |
---|
April 06, 2007 [Issue 1101] New: Can't not deduce template correctly | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=1101 Summary: Can't not deduce template correctly Product: D Version: 1.010 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: davidl@126.com 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)(); } -- |
April 06, 2007 [Issue 1101] Can't not deduce template correctly | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1101 thomas-dloop@kuehne.cn changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #1 from thomas-dloop@kuehne.cn 2007-04-06 04:14 ------- # 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); -- |
April 09, 2007 [Issue 1101] Can't not deduce template correctly | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1101 davidl@126.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|INVALID | ------- Comment #2 from davidl@126.com 2007-04-09 04:10 ------- 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 -- |
April 09, 2007 [Issue 1101] Can't not deduce template correctly | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1101 fvbommel@wxs.nl changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED Resolution| |INVALID ------- Comment #3 from fvbommel@wxs.nl 2007-04-09 05:24 ------- 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. -- |
April 09, 2007 [Issue 1101] Can't not deduce template correctly | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1101 ------- Comment #4 from davidl@126.com 2007-04-09 10:58 ------- 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) -- |
Copyright © 1999-2021 by the D Language Foundation