On Wednesday, 15 March 2023 at 19:22:32 UTC, Paul Backus wrote:
On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote:
[...]
Currently the best workaround for this is to define `Vector` as
a `struct` with `alias this` instead of as an `alias`:
```d
struct Matrix(S, size_t M, size_t N)
{
// ...
}
//alias Vector(S, size_t N) = Matrix!(S, N, 1);
struct Vector(S, size_t N)
{
Matrix!(S, N, 1) data;
alias data this;
// forward constructor calls to wrapped object
this(this This, Args...)(auto ref Args args)
{
import core.lifetime: forward;
data = forward!args;
}
}
void foo(U)(Vector!(U, 3) a)
{
import std.stdio;
writeln("Called with U = ", U.stringof);
}
void main()
{
Vector!(float, 3) v;
foo(v); // ok
}
```
There's a problem with this approach: I'll have to specialize
`Vector Matrix.opBinary(Vector)`. I don't plan to separate my
Vector from Matrix yet. :(