Does `is` expression with template alias need fixing.
Elfstone
elfstone at yeah.net
Wed Mar 15 06:47:38 UTC 2023
```D
struct Matrix(S, size_t M, size_t N)
{
}
alias Vec3(S) = Matrix!(S, 3, 1);
void foo(U)(U v) if (is(U == Vec3!S, S))
{
}
void bar(U)(Vec3!U v) {
}
void main()
{
import std.stdio;
Vec3!float v;
writeln(is(typeof(v) == Vec3!S, S)); // false
// bar(v); // Error, no bar callable using Matrix!(float, 3,
1). huh!
// foo(v); // Error, doesn't satisfy constraint.
}
```
*This is related to DIP1023.
Since we can't use template alias parameters at the moment, how
about making writing a constraint more straightforward?
Honestly, this looks like a bugged design:
```D
writeln(is(Vec3!float == Vec3!S, S)); // false
```
I can live with macros than this.
I have no idea how the compiler works, but I have the feeling
fixing `is` also fixes template alias parameters but anyways,
even if I 'm OK with the excuse that "constraints are enough", I
don't like the idea of writing `Matrix!(S, 3, 1)` a second time
to create the constraint.
More information about the Digitalmars-d
mailing list