std.traits : Select - could it be better?
Steven Schveighoffer
schveiguy at yahoo.com
Thu Jul 5 20:27:29 UTC 2018
On 7/5/18 2:50 PM, SrMordred wrote:
> alias U = Select!( isPointer!T, PointerTarget!T, T );
>
> This don´t compile if T are not a pointer;
>
> so you have to do this:
>
> static if( isPointer!T )
> alias U = PointerTarget!T;
> else
> alias U = T;
>
> Shouldnt the 'correct' way of Select to work is ignoring the choice that
> was not taken?
>
> I love the idea of Select, but because of this I almost never use it.
Hm... only thing I can think of is to do the instantiation within the
template itself:
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);
}
alias U = BetterSelect!(isPointer!T, PointerTarget, Alias, T)
Of course, this requires you to have templates that take EXACTLY the
same parameters.
I don't know if this (or something like it) is worth adding to
std.traits or std.meta.
-Steve
More information about the Digitalmars-d
mailing list