www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - C#4 Covariance/Contravariance

reply bearophile <bearophileHUGS lycos.com> writes:

http://codepad.org/kQgbwAqJ

Bye,
bearophile
Jun 07 2009
parent reply "Lionello Lunesu" <lionello lunesu.remove.com> writes:
"bearophile" <bearophileHUGS lycos.com> wrote in message 
news:h0ggl7$60f$1 digitalmars.com...

 http://codepad.org/kQgbwAqJ

 Bye,
 bearophile
Lionello likes this
Jun 09 2009
parent reply Robert Fraser <fraserofthenight gmail.com> writes:
Lionello Lunesu wrote:
 
 "bearophile" <bearophileHUGS lycos.com> wrote in message 
 news:h0ggl7$60f$1 digitalmars.com...

 http://codepad.org/kQgbwAqJ

 Bye,
 bearophile
Lionello likes this
In D if you want to treat a Template!(SomeClass) as a Template!(Object), it's as easy as "cast(Template!(Object)) cast(void*) x"
Jun 09 2009
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Robert Fraser:
 In D if you want to treat a Template!(SomeClass) as a Template!(Object), 
 it's as easy as "cast(Template!(Object)) cast(void*) x"
How is this related to Covariance/Contravariance and in/out keywords, as shown Bye, bearophile
Jun 09 2009
parent reply Robert Fraser <fraserofthenight gmail.com> writes:
bearophile wrote:
 Robert Fraser:
 In D if you want to treat a Template!(SomeClass) as a Template!(Object), 
 it's as easy as "cast(Template!(Object)) cast(void*) x"
How is this related to Covariance/Contravariance and in/out keywords, as shown Bye, bearophile
Errr... isn't that the point of covariance/contravariance?
Jun 09 2009
parent bearophile <bearophileHUGS lycos.com> writes:
Robert Fraser:
 Errr... isn't that the point of covariance/contravariance?
I don't know some of the things I post here. I just assume people here know better than me. Bye, bearophile
Jun 10 2009
prev sibling parent reply "Lionello Lunesu" <lionello lunesu.remove.com> writes:
"Robert Fraser" <fraserofthenight gmail.com> wrote in message 
news:h0mui6$2rlh$1 digitalmars.com...
 Lionello Lunesu wrote:
 "bearophile" <bearophileHUGS lycos.com> wrote in message 
 news:h0ggl7$60f$1 digitalmars.com...

 http://codepad.org/kQgbwAqJ

 Bye,
 bearophile
Lionello likes this
In D if you want to treat a Template!(SomeClass) as a Template!(Object), it's as easy as "cast(Template!(Object)) cast(void*) x"
Does not work for interfaces though. L.
Jun 09 2009
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Lionello Lunesu wrote:
 
 "Robert Fraser" <fraserofthenight gmail.com> wrote in message
 news:h0mui6$2rlh$1 digitalmars.com...
 Lionello Lunesu wrote:
 "bearophile" <bearophileHUGS lycos.com> wrote in message
 news:h0ggl7$60f$1 digitalmars.com...

 http://codepad.org/kQgbwAqJ

 Bye,
 bearophile
Lionello likes this
In D if you want to treat a Template!(SomeClass) as a Template!(Object), it's as easy as "cast(Template!(Object)) cast(void*) x"
Does not work for interfaces though. L.
Hell, it's not even safe. class Template(T) { static T instance; final T getInstance() { return instance; } } Or class Template(T) { static if( is( T == SomeClass ) ) { bool boom() { return true; } } void stuff(); } (cast(Template!(Object)) cast(void*) new Template!(SomeClass)).stuff();
Jun 09 2009