Thread overview
[Issue 7657] New: ReturnType fails for simple templated functions
Mar 07, 2012
Andrej Mitrovic
Mar 07, 2012
Jonathan M Davis
Apr 20, 2012
Andrej Mitrovic
March 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7657

           Summary: ReturnType fails for simple templated functions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-03-06 17:51:58 PST ---
import std.algorithm;
import std.traits;

void main()
{
    alias ReturnType!countUntil Type;  // fails
}

Here's the thing: countUntil has a defined return type and it doesn't change based on its template arguments. So I think the above should work.

I'm doing some metaprogramming and I need to get the return type of a function so I can wrap it. I can't simply use 'auto' because I'm also wrapping the return type, e.g.:

template Magic(alias func)
{
    Wrapped!(ReturnType!func) Magic(T...)(T t)
    {
         // ..
    }
}

I think ReturnType could be made to work even though it's a non-instantiated template (I'm not sure how but maybe there's a way).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7657


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-03-06 17:58:09 PST ---
Except that if a template hasn't been initialized, it doesn't even really _exist_ as far as the compiler is concerned. It's a template for something, not an actual function or type.

So, while I can see why you'd want this, I just don't see how it could be done with how templates are implemented.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7657


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

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


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-04-19 19:13:53 PDT ---
(In reply to comment #1)
> Except that if a template hasn't been initialized, it doesn't even really _exist_ as far as the compiler is concerned. It's a template for something, not an actual function or type.
> 
> So, while I can see why you'd want this, I just don't see how it could be done with how templates are implemented.

Yes, and come to think of it it would be dangerous to allow this feature. If at a later time a template had its return type changed to 'auto' it would break existing code that relied on ReturnType working on such a template.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------