contravariant argument types: wanna?
Steven Schveighoffer
schveiguy at yahoo.com
Thu Sep 24 09:24:18 PDT 2009
On Thu, 24 Sep 2009 11:53:13 -0400, Jeremie Pelletier <jeremiep at gmail.com>
wrote:
> Steven Schveighoffer wrote:
>> The Tango lib used to define Input and Output streams independent of
>> Seekable streams (there was a Seek interface which was applied
>> separately to an input/output implementation class).
>> But what ends up happening is that it was unwieldly to use streams in
>> cases where seeking is used, because you have to dynamic-cast to the
>> seek interface to determine if seeking is available.
>
> interface ISeekableInputStream : IInputStream, ISeekableStream {}
You'd think this works well, but it still doesn't cut it. There are about
a dozen filter classes in tango that would have to have seekable and
non-seekable versions. This was the original problem (that you couldn't
seek the filter classes).
> Covariant arguments is something you're gonna come across at some point
> or another. Having language support for it does not make it the rule,
> but a convenience for the exception.
Having language support makes it not an exception, even if it's not the
rule. The reason it's not automatic is because the language designer
wants you to know "hey, you're doing something that isn't cheap." Just
silently allowing it makes for code that too easily can call multiple
dynamic casts every time you call a method.
-Steve
More information about the Digitalmars-d
mailing list