Trying to do alias template deduction myself.
Salih Dincer
salihdb at hotmail.com
Mon Apr 3 19:50:14 UTC 2023
On Monday, 3 April 2023 at 12:56:10 UTC, Elfstone wrote:
>
> I'm almost sure my code works with bare type identifiers and
> values. I can probably support tuple soon. I'll figure out what
> I can do with fancy U:U*, U: A!U, etc.
Why don't you try using AliasSeq? I think it would be very
elegant with a triple staticMap. For example:
```d
import std.meta;
struct Matrix(U, size_t M, size_t N)
{
U[M * N] data;
}
alias P = AliasSeq!(byte, short, int);
alias X = AliasSeq!(3, 3, 4);
alias Y = AliasSeq!(1, 3, 2);
void main()
{
alias Vec3(U) = Matrix!(U, 3, 3);
alias T = float;
Vec3!T cube;
void singleMatrix(U)(Vec3!U v){}
singleMatrix!T(cube); // ok
assert(is(typeof(cube) == Vec3!T));
// ...
alias Vec3Var(U...) = staticMapTrio!(Matrix, U);
alias S = AliasSeq!(P, X, Y);
Vec3Var!S trio;
void triMatrix(U...)(in Vec3Var!(U) v){}
triMatrix!S(trio); // ok
assert(is(typeof(trio) == Vec3Var!S));
}
template staticMapTrio(alias fun, args...) {
alias staticMapTrio = AliasSeq!();
static foreach (i; 0..args.length / 3) {
staticMapTrio = AliasSeq!(staticMapTrio,
fun!(args[0..$/3][i],
args[$/3..($/3) * 2][i],
args[($/3) * 2..($/3) * 3][i]
)
);
}
}
```
More information about the Digitalmars-d
mailing list