Re: Specialization with generics
From: Sean Hederman (usemy_at_blogentry.com)
Date: 03/07/05
- Next message: Sean Hederman: "Re: pure virtual (as in C++)"
- Previous message: Avinash: "Re: How to use Stackframe and stacktrace in Windows Service"
- In reply to: Michael Sparks: "Specialization with generics"
- Next in thread: Helge Jensen: "Re: Specialization with generics"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Sean Hederman: "Re: pure virtual (as in C++)"
- Previous message: Avinash: "Re: How to use Stackframe and stacktrace in Windows Service"
- In reply to: Michael Sparks: "Specialization with generics"
- Next in thread: Helge Jensen: "Re: Specialization with generics"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|