Template type deduction

Phil Lavoie maidenphil at hotmail.com
Sun Jan 20 08:01:55 PST 2013


On Sunday, 20 January 2013 at 15:39:53 UTC, Philippe Sigaud wrote:
> On Sun, Jan 20, 2013 at 3:59 PM, Phil Lavoie 
> <maidenphil at hotmail.com> wrote:
>> Imagine you have something like this:
>>
>> struct MyParamType( T1, T2 ) { ... }
>>
>> and then a compound:
>>
>> struct MyCoumpound( T ) if( isMyParamType!T ) { ... }
>>
>> template isMyParamType( T ) {
>>   enum isMyParamType = ... //Complete this
>> }
>>
>> Is it possible to deduce that T is a parameterized struct using
>> isExpressions:
>>
>> enum isMyParamType = is( T U: MyParamType!U ); //Works for 1 
>> parameter, but
>> what do you do when you have plenty?
>
> This should work:
>
> is(T _ : MyParamType!U, U...)
>
>
> ( '_' just to tell someone reading the code this part is not 
> used)

Is there also a way to extract per parameter information (ex: 
type) using type deduction. Let me illustrate:

struct Toto( T1, T2 ) {
  alias Key = T1;
  alias Value = T2;
}

struct OuterToto( T ) if( isToto!T ) {
   T.Key key;
   T.Value value;
}

Imagine I would want that but without using inner aliases, is 
this possible?

Thanks!
Phil


More information about the Digitalmars-d-learn mailing list