Base type for arrays

Namespace via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 17 14:02:13 PDT 2015


On Wednesday, 17 June 2015 at 20:58:10 UTC, jmh530 wrote:
> On Wednesday, 17 June 2015 at 20:33:11 UTC, Namespace wrote:
>> ----
>> import std.stdio;
>>
>> template BaseTypeOf(T) {
>>     static if (is(T : U[], U))
>>         alias BaseTypeOf = BaseTypeOf!(U);
>>     else
>>         alias BaseTypeOf = T;
>> }
>>
>> void foo(T : U[], U)(T arr) if (is(BaseTypeOf!(U) == real)) {
>> 	
>> }
>>
>> void main() {
>> 	//real _x;
>> 	real[2] x;
>> 	real[2][2] xx;
>> 	real[2][2][2] xxx;
>> 	
>> 	//float[2] yy;
>> 	
>> 	//foo(_x);
>> 	foo(x);
>> 	foo(xx);
>> 	foo(xxx);
>> 	
>> 	//foo(yy);
>> }
>> ----
>>
>> should work
>
> Thanks. I'm going to make a lot of use of this. I would say it 
> deserves to be in std.traits.

Maybe you can also make use of some of those here (just in case):
https://github.com/Dgame/m3/blob/master/source/m3/m3.d


More information about the Digitalmars-d-learn mailing list