www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6082] New: Constructors of templated types should be callable vi IFTI

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6082

           Summary: Constructors of templated types should be callable vi
                    IFTI
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: schveiguy yahoo.com



12:36:46 PDT ---
If I have the following class:

class A(T)
{
   this(T t) {}
}

I must specify the class type in order to call its constructor:

auto a = new A(1); // error
auto b = new A!int(1); // ok

But IFTI works in this instance:

template foo(T)
{
   void foo(T t) {}
}

I see little difference between the first and second cases -- both must be
partially instantiated by the compiler to determine if there is a valid
function to call.

Further supporting this, I can add a factory function:

A(T) createA(T)(T t) { return new A!T(t); }

which now is callable via IFTI:

auto a = createA(1); // ok.

It seems like the necessary logic is present in the compiler, it just needs to
be utilized during a constructor call.

The same should apply to structs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6082




15:54:21 PDT ---
Also see DIP 40: http://wiki.dlang.org/DIP40

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