Closest Common Type

Bill Baxter dnewsgroup at billbaxter.com
Fri May 16 11:54:55 PDT 2008


BCS wrote:
> Reply to Lutger,
> 
>> BCS wrote:
>>
>>> I have a tuple of types, I want a template that evaluates to the most
>>> specialized base type of all of them. I'll be using it for classes
>>> but for other cases it just needs to do something sane (erroring out
>>> would do).
>>>
>>> No point in reinventing the wheel so, anyone have such a template
>>> laying around?
>>>
>> tango.core.Tuple and std.typetuple have templates called MostDerived
>> and DerivedToFront, these might be helpful?
>>
> 
> I might be able to use somthing like that as a starting point but what I 
> want is this
> 
> class A {}
> class B : A {}
> class C : A {}
>  class D : C {}
>  class E : C {}
> class F {}
> 
> CCT!(E, D) // == C
> CCT!(E, C) // == C
> CCT!(E, B) // == A
> CCT!(E, A) // == A
> CCT!(E, F) // == object

That sounds like the kind of thing that you're supposed to be able to 
get from typeof(true?E.init:D.init), but I seem to recall a bug filed by 
  Andrei the other day saying it doesn't work properly for classes.

--bb


More information about the Digitalmars-d-learn mailing list