equivariant functions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 12 13:19:50 PDT 2008


Christopher Wright wrote:
> All your examples use typeof(something). Is the intent to make this 
> example work?
>  > class A { A clone(); }
>  > class B : A { B clone(); }

That example does work today. It's covariance of return values and is 
only loosely related to this topic.

> I take it that this would also extend to delegates?
> 
> class A {}
> class B : A {}
> 
> void foo (A delegate (A) dg) { }
> B bar (B b) { }
> foo (&bar);
> 
> If you require "typeof(something)", I'd never use this feature. 
> Otherwise, I'd use it sometimes.

The example is wrong because B delegate(B) is not a supertype nor a 
subtype of A delegate(A). The proposed solution does involve writing 
typeof as an indication of the need to return the same type as the 
argument's.


Andrei



More information about the Digitalmars-d mailing list