Swap furthest element type of an array

Timon Gehr timon.gehr at gmx.ch
Mon Jun 18 18:48:34 PDT 2012


On 06/19/2012 12:01 AM, Andrej Mitrovic wrote:
> On 6/18/12, Timon Gehr<timon.gehr at gmx.ch>  wrote:
>> template SwapElem(A, E){
>>       static if(is(A X:X[N],size_t N)) alias SwapElem!(X,E)[N] R;
>>       else static if(is(A X:X[])) alias SwapElem!(X,E)[] R;
>>       else static if(is(A X:X*)) alias SwapElem!(X,E)* R;
>>       else alias E R;
>>       alias R SwapElem;
>> }
>>
>> pragma(msg, SwapElem!(int[]*[3][]*[2][]*[1][], float));
>>
>
> Niiiice! Did you just come up with this right now? :D

Indeed. If you are interested, I'll make it work with qualified types as 
well. =)


More information about the Digitalmars-d-learn mailing list