Templates convariance
michal.minich at gmail.com
michal.minich at gmail.com
Tue Jun 20 10:46:21 PDT 2006
Thank you for casting solution. It should works perfect for my problem. But
could you explain me how this can mess things up?
In article <e79amd$2kil$1 at digitaldaemon.com>, Tom S says...
>
>Frankly, I wouldn't like to see that 'template covariance' in D. It
>would mess things up... How about doing something like:
>
>class List(T) {
> template asList(T1) {
> .List!(T1) asList() {
> static if (is(T : T1)) {
> return cast(.List!(T1))cast(void*)this;
> } else {
> return null; // or static assert (false)
> }
> }
> }
>}
>
>
>then you might write:
>
>auto circleList = new List!(Circle);
>auto shapeList = circleList.asList!(Shape);
>
>
>
>--
>Tomasz Stachowiak /+ a.k.a. h3r3tic +/
More information about the Digitalmars-d
mailing list