Thread overview
[Issue 9365] New: Allow partially specified template aliases
Jan 21, 2013
Peter Alexander
Jan 21, 2013
Andrej Mitrovic
Jan 21, 2013
Peter Alexander
Jan 22, 2013
yebblies
Jun 10, 2013
Peter Alexander
January 21, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9365

           Summary: Allow partially specified template aliases
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: peter.alexander.au@gmail.com


--- Comment #0 from Peter Alexander <peter.alexander.au@gmail.com> 2013-01-21 12:50:45 PST ---
It would be helpful if it were possible to alias partially specified templates. An example:

void foo(A, B)() {}

alias foo!int fooInt;

Currently this fails with "Error: template instance foo!(int) foo!(int) does
not match template declaration foo(A, B)()".

However, if you write foo as:

template foo(A)
{
    void foo(B)() {}
}

Then it works.

This would be useful because it would allow you to write things like:

alias equalRoR = equal!equal;

instead of having to write:

alias equalRoR = binaryFun!((a, b) => equal!equal(a, b));

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 21, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9365


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-21 13:15:33 PST ---
This can be implemented in the library, the last thing you want is for templates being partially instantiated when you pass too few arguments instead of getting an error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 21, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9365



--- Comment #2 from Peter Alexander <peter.alexander.au@gmail.com> 2013-01-21 15:11:58 PST ---
(In reply to comment #1)
> This can be implemented in the library, the last thing you want is for templates being partially instantiated when you pass too few arguments instead of getting an error.

There will be no partial instantiation (what it that anyway?)

What I'm asking for is a rewrite from:

alias A = B!(x, y);

to

alias A = ((args...) => B!(x, y)(args)); // if this was valid syntax

when B has more than 2 non-default template parameters. The rest are determined using type deduction when A is invoked.

This is frustrating:

void foo(A, B)(A a, B b) {}

foo(1, 2); // OK
foo!(int)(1, 2); // OK
foo!(int, int)(1, 2); // OK

alias X = foo; // OK
alias Y = foo!(int); // ERROR
alias Z = foo!(int, int); // OK

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9365


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com


--- Comment #3 from yebblies <yebblies@gmail.com> 2013-01-22 15:19:02 EST ---
Something like

alias A(T) = B!(x, T);

Is more likely and more flexible.

Expanding to:

template A(T)
{
    alias A B!(x, T)
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9365



--- Comment #4 from Peter Alexander <peter.alexander.au@gmail.com> 2013-06-09 23:35:09 PDT ---
(In reply to comment #3)
> Something like
> 
> alias A(T) = B!(x, T);
> 
> Is more likely and more flexible.

See my use case, with your suggestions, this wouldn't work:

alias equalRoR = equal!equal;

An alternative suggestion, is to change how function templates are expanded. Currently we have:

void foo(A, B)(A a, B b)

expanding to

template foo(A, B)
{
    void foo(A a, B b);
}

If instead, it expanded to:

template foo(A)
{
    template foo(B)
    {
        void foo(A a, B b);
    }
}

Then foo!int becomes a valid, alias-able symbol, which would solve the problem as well.

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