www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1462] New: Templated constructor not supported

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

           Summary: Templated constructor not supported
           Product: D
           Version: 2.003
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: reiner.pope gmail.com


I know of no way to create a templated constructor for a class. (This is
useful, for instance, with variadic template args). The following code fails to
parse in compilation:

class Foo
{
    this(T...)(T t) {}
}


-- 
Aug 31 2007
next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1462


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Severity|normal                      |enhancement
           Keywords|                            |spec





The problem seems to be that the current D syntax doesn't support it:

Constructor:
        this Parameters FunctionBody

Parameters:
        ( ParameterList )
        ( )

The alternative would be

class Foo
{
    template(T...) this {
        this(T t) {}
    }
}

except that this doesn't work because 'this' is a keyword, not an identifier.


-- 
Sep 09 2008
parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Tue, Sep 9, 2008 at 1:32 PM,  <d-bugmail puremagic.com> wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1462


 smjg iname.com changed:

           What    |Removed                     |Added
 ----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Severity|normal                      |enhancement
           Keywords|                            |spec





 The problem seems to be that the current D syntax doesn't support it:

 Constructor:
        this Parameters FunctionBody

 Parameters:
        ( ParameterList )
        ( )

 The alternative would be

 class Foo
 {
    template(T...) this {
        this(T t) {}
    }
 }

 except that this doesn't work because 'this' is a keyword, not an identifier.


 --
I think it's much more that templated methods cannot be virtual, and constructors more or less have to be.
Sep 09 2008
next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Tue, 09 Sep 2008 22:48:01 +0400, Jarrett Billingsley  
<jarrett.billingsley gmail.com> wrote:

 On Tue, Sep 9, 2008 at 1:32 PM,  <d-bugmail puremagic.com> wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1462


 smjg iname.com changed:

           What    |Removed                     |Added
 ----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Severity|normal                      |enhancement
           Keywords|                            |spec





 The problem seems to be that the current D syntax doesn't support it:

 Constructor:
        this Parameters FunctionBody

 Parameters:
        ( ParameterList )
        ( )

 The alternative would be

 class Foo
 {
    template(T...) this {
        this(T t) {}
    }
 }

 except that this doesn't work because 'this' is a keyword, not an  
 identifier.


 --
I think it's much more that templated methods cannot be virtual, and constructors more or less have to be.
How about struct constructors?
Sep 09 2008
prev sibling parent reply Sean Kelly <sean invisibleduck.org> writes:
Jarrett Billingsley wrote:
 
 I think it's much more that templated methods cannot be virtual, and
 constructors more or less have to be.
How are constructors virtual? Sean
Sep 09 2008
parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Tue, Sep 9, 2008 at 3:55 PM, Sean Kelly <sean invisibleduck.org> wrote:
 Jarrett Billingsley wrote:
 I think it's much more that templated methods cannot be virtual, and
 constructors more or less have to be.
How are constructors virtual?
Uhh umm Well as it is now, constructors are treated as methods of the class, so they participate in overloading. But I think you're right - it doesn't really seem to have to be that way.
Sep 09 2008
parent reply Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Jarrett Billingsley wrote:
 On Tue, Sep 9, 2008 at 3:55 PM, Sean Kelly <sean invisibleduck.org> wrote:
 Jarrett Billingsley wrote:
 I think it's much more that templated methods cannot be virtual, and
 constructors more or less have to be.
How are constructors virtual?
Uhh umm Well as it is now, constructors are treated as methods of the class, so they participate in overloading. But I think you're right - it doesn't really seem to have to be that way.
That makes no sense :p . Not only are they not virtual, they could never be virtual. Virtual method dispatch is used when you have polymorphism and don't know the exact class of the receiving object. But when constructing you always know the exact class being creating, so you would always know which method/constructor/whatever to dispatch to. -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Sep 11 2008
parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Thu, Sep 11, 2008 at 5:53 AM, Bruno Medeiros
<brunodomedeiros+spam com.gmail> wrote:
 Jarrett Billingsley wrote:
 On Tue, Sep 9, 2008 at 3:55 PM, Sean Kelly <sean invisibleduck.org> wrote:
 Jarrett Billingsley wrote:
 I think it's much more that templated methods cannot be virtual, and
 constructors more or less have to be.
How are constructors virtual?
Uhh umm Well as it is now, constructors are treated as methods of the class, so they participate in overloading. But I think you're right - it doesn't really seem to have to be that way.
That makes no sense :p . Not only are they not virtual, they could never be virtual. Virtual method dispatch is used when you have polymorphism and don't know the exact class of the receiving object. But when constructing you always know the exact class being creating, so you would always know which method/constructor/whatever to dispatch to.
Then beat Walter over the head!
Sep 11 2008
parent Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Jarrett Billingsley wrote:
 On Thu, Sep 11, 2008 at 5:53 AM, Bruno Medeiros
 <brunodomedeiros+spam com.gmail> wrote:
 Jarrett Billingsley wrote:
 On Tue, Sep 9, 2008 at 3:55 PM, Sean Kelly <sean invisibleduck.org> wrote:
 Jarrett Billingsley wrote:
 I think it's much more that templated methods cannot be virtual, and
 constructors more or less have to be.
How are constructors virtual?
Uhh umm Well as it is now, constructors are treated as methods of the class, so they participate in overloading. But I think you're right - it doesn't really seem to have to be that way.
That makes no sense :p . Not only are they not virtual, they could never be virtual. Virtual method dispatch is used when you have polymorphism and don't know the exact class of the receiving object. But when constructing you always know the exact class being creating, so you would always know which method/constructor/whatever to dispatch to.
Then beat Walter over the head!
Apparently my cluebat doesn't reach all the way to Seattle! -_-' -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Sep 15 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1462


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |schveiguy yahoo.com
         Resolution|                            |DUPLICATE



10:57:21 PDT ---
*** This issue has been marked as a duplicate of issue 435 ***

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