Comment #0 by andrej.mitrovich — 2023-01-09T12:56:41Z
-----
import std.typecons;
struct Vec {
this(int, int, int) {
}
}
void main() {
auto v1 = Vec(1, 2, 3); // ok
alias TVec = Typedef!Vec;
auto v2 = TVec(1, 2, 3); // error
}
-----
$ dmd test.d
> test.d(13): Error: none of the overloads of `this` are callable using argument types `(int, int, int)`
Comment #1 by andrej.mitrovich — 2023-01-09T13:10:33Z
For anyone else who just wants to "get things done", I use this sort of workaround:
-----
private struct Vec3(size_t line = __LINE__)
{
...
}
// Type aliases for Vec3
public alias Point3 = Vec3!(); // 3D point
public alias Color = Vec3!(); // RGB color
-----
So at least that gives you some type safety.
And that only works for your own user-defined types. But you could use alias this tricks to wrap existing types. Maybe Typedef does something like this under the hood. But it's so incomplete it's a pain to use.
Comment #2 by robert.schadek — 2024-12-01T16:41:01Z