www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12433] New: Allow forward referencing IFTI types in template argument list

https://d.puremagic.com/issues/show_bug.cgi?id=12433

           Summary: Allow forward referencing IFTI types in template
                    argument list
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: thecybershadow gmail.com


--- Comment #0 from Vladimir Panteleev <thecybershadow gmail.com> 2014-03-21
20:17:57 EET ---
Consider this hypothetical example:

///////////////// test.d /////////////////
T[] copyArray(T=I, I)(I[] input)
{
    auto result = new T[input.length];
    foreach (n, ref i; input)
        result[n] = i;
    return result;
}

void main()
{
    // copy as is
    int[] r1 = copyArray([1, 2, 3]);
    // copy to another type
    long[] r2 = copyArray!long([1, 2, 3]);
}
//////////////////////////////////////////

There is currently no way to get this code to work, without either declaring an
overload for copyArray, or replacing T=I with T=SomeDummyType and later
checking to see if something was explicitly passed or not.

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