Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 31, 2007 [Issue 1462] New: Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
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) {} } -- |
September 09, 2008 [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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 ------- Comment #1 from smjg@iname.com 2008-09-09 12:32 ------- 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. -- |
September 09, 2008 Re: [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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
>
>
>
>
> ------- Comment #1 from smjg@iname.com 2008-09-09 12:32 -------
> 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.
|
September 09, 2008 Re: [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 >> >> >> >> >> ------- Comment #1 from smjg@iname.com 2008-09-09 12:32 ------- >> 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? |
September 09, 2008 Re: [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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
|
September 09, 2008 Re: [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | 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.
|
September 11, 2008 Re: [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 |
September 11, 2008 Re: [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | 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! |
September 15, 2008 Re: [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 |
August 05, 2010 [Issue 1462] Templated constructor not supported | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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 --- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> 2010-08-05 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: ------- |
Copyright © 1999-2021 by the D Language Foundation