Base type for arrays
jmh530 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 17 13:58:09 PDT 2015
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.
More information about the Digitalmars-d-learn
mailing list