struct Matrix(S, size_t M, size_t N)
{
}
alias Vector(S, size_t N) = Matrix!(S, N, 1);
enum isVector(V) = is(V == Vector!(S, N), S, size_t N); // it doesn't work
enum isVectorCorrect(V) = is(V == Matrix!(U, N, 1), U, size_t N); // the "correct" way and how much I like to REPEAT myself!
void foo(U)(Vector!(U, 3) a)
{
}
void bar(U)(U a) if (isVector!U)
{
}
void main()
{
import std.stdio;
Vector!(float, 3) v;
foo(v); // Error: none of the overloads of template `app.doSomething` are callable using argument types `!()(Matrix!(float, 3LU, 1LU))
bar(v); // failed constraint isVector!U
}
I went back to some of my old code and couldn't stand what I had ended up with - If I already have a well-defined Vector
, why do I have to write extra code to implement isVector
, and use isVector
instead of simply declaring the param to be Vector
?
But that's simply the current state: it looks like DIP1023 isn't going anywhere, and I'm not a compiler expert.
Note that I had to repeat Matrix!(S, N, 1)
to for both Vector
and isVector
.
Is there a way around this?!
--
It can get worse.
alias Vec2(S) = Vector!(S, 2);
alias Vec3(S) = Vector!(S, 3);
enum isVec3(V) = is(V == Matrix!(S, 2, 1), S);
enum isVec3(V) = is(V == Matrix!(S, 3, 1), S);
void foobar(U)(U v) if (isVec3!U);
It works, but it hurts my eyes.