Templates convariance

Tom S h3r3tic at remove.mat.uni.torun.pl
Tue Jun 20 10:19:02 PDT 2006


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