std.traits : Select - could it be better?

SrMordred patric.dexheimer at gmail.com
Fri Jul 6 02:17:51 UTC 2018


On Thursday, 5 July 2018 at 20:29:02 UTC, Steven Schveighoffer 
wrote:
> On 7/5/18 4:27 PM, Steven Schveighoffer wrote:
>> template BetterSelect(bool cond, alias temp1, alias temp2, 
>> Args...)
>> {
>>     import std.meta : Instantiate;
>>     static if(cond)
>>        alias BetterSelect = Instantiate!(temp1, Args);
>>     else
>>        alias BetterSelect = Instantiate!(temp2, Args);
>> }
>
> ugh, got too cute for my own good :) No need for Instantiate 
> here:
>
> alias BetterSelect = temp1!Args;
> alias BetterSelect = temp2!Args;
>
> -Steve

I find another solution :)

template Try(alias T, Args...)
{
     static if( is( T!Args ) )
         alias Try = T!Args;
}

alias U = Select!( isPointer!T, Try!( PointerTarget, T ), T );



More information about the Digitalmars-d mailing list