--- Comment #11 from Andrei Alexandrescu <> 2011-04-06 
13:26:45 PDT ---
(In reply to comment #10)
> (In reply to comment #9)
> > One can always connect an imaginary root to all rootless interfaces and 
> > apply
> > the rule I mentioned. Let me add that "?:" is a cornerstone operator for a 
> > lot
> > of traits and type deduction paraphernalia (e.g. std.traits.CommonType). I
> > wouldn't insist in the matter if it weren't important beyond the 
> > convenience of
> > "?:" itself.
> I agree about the importance of the ?: algorithm. But I wonder if the compiler
> picking a common ancestor from a complex inheritance graph is really a good
> thing - it may prove surprising to the user. For example:
> interface A : B,C,D,E
> interface X : M,N,O,C
> Is it really the right idea to pick C for the common type? I'm skeptical.

Yes, in this case D is unequivocally the common type. A more interesting
example is:

interface A {}
interface B {}
interface C : B {}
interface X : A, C {}
interface Y : A, C {}

By my suggested rule, C would be the common type as it's the most specific
(most remote from a root). At the same time both A and C are equally distanced
from X and Y so it's legitimate to ask on why A is not an equally good fit (and
therefore an ambiguity).

A rule that would avoid that issue would be to count all common ancestors and
find the one that is closest to both, i.e. shortest sum of steps from both
interfaces. I thought of it but eliminated it because it can create rather
subtle distinctions.

I agree the problem is not as clear cut as we'd like. OP?

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to