www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1101] New: Can't not deduce template correctly

reply d-bugmail puremagic.com writes:
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)();
}


-- 
Apr 05 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1101


thomas-dloop kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID











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:







and








-- 
Apr 06 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1101


davidl 126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |





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


-- 
Apr 09 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1101


fvbommel wxs.nl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID





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.


-- 
Apr 09 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1101






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)


-- 
Apr 09 2007