Re: Specialization with generics

From: Sean Hederman (usemy_at_blogentry.com)
Date: 03/07/05


Date: Mon, 7 Mar 2005 07:05:47 +0200

No, user-defined specialization is not supported by generics. Apparrently
the designers felt that user-defined specialization was too tied to C++.
Since most other differences between templates and generics are emergent
from the different instantiation times (compile-time for templates, run-time
for generics) I wouldn't be too surprised if this had an impact on
user-defined specialization as well.

"Michael Sparks" <mike@remove.this.sparks.name> wrote in message
news:2Zudnew7CcZG47bfRVn-pg@comcast.com...
>I started writing some code with the 2.0 beta compiler, and found out
>quickly that specialization is not supported with generics.
>
> For example, I want to do something like this:
>
> class number ...
> class integer : number ...
> class real : number ...
> class multiplier<_number> where _number : number ...
> class multiplier<_number> where _number : integer ...
>
> Here, the first implementation of 'multiplier' will work with 'number' or
> anything that derives from 'number'. The second implementation of
> 'multiplier' will work with 'integer' or anything that derives from
> 'integer. Since 'integer' derives from 'number', it is a specialization.
> At least that's what I'm calling it - there may be a more appropriate name
> in this exact context.
>
> This may be preaching to the choir - I haven't been in this newsgroup for
> a while, but here is an example of where it would be useful to have the
> above feature:
>
> class fancy_computation<_number> where _number : number
> {
> public _number doit(_number x,_number y)
> {
> multiplier<_number> mult=new multiplier<_number>;
> return mult.doit(x,y);
> }
> }
>
> The advantage here is that I can type 'fancy_computation<integer>' and the
> compiler will automatically select the correct implementation of
> 'multiplier'.
>
> Anyway, it look like this is not supported. I am wondering what specific
> limitation caused the design team to leave out support for specialization.
>
> Thanks for any insight you can provide.
>
> Mike



Relevant Pages

  • Re: Unmanaged Possibilities
    ... particular how to use templates to enable use of generics. ... generics is compile time support and not runtime support (as ... "Rossen Assenov" type Delphi generics: ...
    (borland.public.delphi.non-technical)
  • Re: templates and managed code
    ... Beware that managed generics are *NOT* templates, ... not support specialization, ... Managed C++ allows only interface multiple-inheritance and class single ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Delphi support for generics/templates?
    ... they could invent their own implementation of generics within the ... definitely need to support the MS implementation once added. ... The end result is they'll burn resources now to implement this just to be ... since the result will be one single compatible implementation. ...
    (borland.public.delphi.non-technical)
  • Re: 64-bit on the horizon? (Was Re: Vista Requirement Already)
    ... FAR more important than generics or partial classes, ... (aiui even a .net language doesn't _have_ to support generics, ... My 64-bit servers run all my 32 bit apps just fine. ...
    (borland.public.delphi.non-technical)
  • Re: IDE products roadmap updated
    ... Highlander will add Delphi.NET support for generic types, ... partial classes, and nullable types, and all WinForms, Web Services, and ... ADO.NET support will be converted to support .NET 2.0. ... generics may be the headline feature, but their use tends to be ...
    (borland.public.delphi.non-technical)