| 1 |
template StaticArrayTypeOf(T) |
| 2 |
{ |
| 3 |
inout(U[n]) idx(U, size_t n)( inout(U[n]) ); |
| 4 |
|
| 5 |
/+static if (is(T == enum)) |
| 6 |
alias .StaticArrayTypeOf!(OriginalType!T) StaticArrayTypeOf; |
| 7 |
else +/static if (is(typeof(idx(T.init/+defaultInit!T+/)) X)) |
| 8 |
alias X StaticArrayTypeOf; |
| 9 |
else |
| 10 |
static assert(0, T.stringof~" is not a static array type"); |
| 11 |
} |
| 12 |
|
| 13 |
template DynamicArrayTypeOf(T) |
| 14 |
{ |
| 15 |
inout(U[]) idx(U)( inout(U[]) ); |
| 16 |
|
| 17 |
/+static if (is(T == enum)) |
| 18 |
alias .DynamicArrayTypeOf!(OriginalType!T) DynamicArrayTypeOf; |
| 19 |
else +/static if (!is(StaticArrayTypeOf!T) && |
| 20 |
is(typeof(idx(T.init/+defaultInit!T+/)) X)) |
| 21 |
{ |
| 22 |
alias typeof(T.init[0]/+defaultInit!T[0]+/) E; |
| 23 |
|
| 24 |
E[] idy( E[] ); |
| 25 |
const(E[]) idy( const(E[]) ); |
| 26 |
inout(E[]) idy( inout(E[]) ); |
| 27 |
shared( E[]) idy( shared( E[]) ); |
| 28 |
shared(const E[]) idy( shared(const E[]) ); |
| 29 |
shared(inout E[]) idy( shared(inout E[]) ); |
| 30 |
immutable(E[]) idy( immutable(E[]) ); |
| 31 |
|
| 32 |
alias typeof(idy(T.init/+defaultInit!T+/)) DynamicArrayTypeOf; |
| 33 |
} |
| 34 |
else |
| 35 |
static assert(0, T.stringof~" is not a dynamic array"); |
| 36 |
} |
| 37 |
|
| 38 |
template isDynamicArray(T) |
| 39 |
{ |
| 40 |
enum isDynamicArray = is(DynamicArrayTypeOf!T)/+ && !isAggregateType!T+/; |
| 41 |
} |
| 42 |
|
| 43 |
template isArray(T) |
| 44 |
{ |
| 45 |
enum bool isArray = /+isStaticArray!T || +/isDynamicArray!T; |
| 46 |
} |