[typing] Type-erasure re generics

Jonathan M Davis jmdavisProg at gmx.com
Wed Sep 29 11:39:43 PDT 2010


On Wednesday, September 29, 2010 11:11:53 Steven Schveighoffer wrote:
> I think actually that concept is in the latest C# with type
> contra-variance.
> 
> Essentially, you should be able to implicitly cast Container!(B) to
> const(Container!(A)) conceptually, but actually you may have to require
> only pure calls (I don't think there's a way to do this).
> 
> I think C# deals with this via designating certain types on the template
> parameters as "input" or "output" types, and restricting functions from
> using types in the wrong direction.

There may be a way to get it to work with const or some other sort of 
constraints that disallowed mutation - or at least mutating what is directly in 
the container (mutating which is referred to by the elements in the container 
could work) - but you can't allow mutation of the elements directly in the 
container or you'd be allowed to put incorrect types in the container. I'd hate 
to be the one to try to get such a feature to work without const like they would 
have had to do in C#.

- Jonathan M Davis


More information about the Digitalmars-d mailing list