logoalt Hacker News

dpassens08/10/20251 replyview on HN

If my understanding of D's template syntax is correct, then Walter is showing a the declaration of a function called ArrayListType which is generic over T and returns a T. The original Zig code returns the struct type itself, so it is functionally equivalent to my example, provided I understood how D templates work.


Replies

brabel08/10/2025

The Zig code returns any `type`, it's impossible to say what that is without looking at the implementation. It can be different types completely depending on the comptime arguments.

But I agree it probably returns a struct type.

Assuming that's the case, you're right and the equivalent would be:

Zig:

    fn ArrayListType(comptime T: type) type {
D:

    ArrayList!T ArrayListType(T)() {
But now the D version is more specific about what it returns, so it's still not exactly equivalent.
show 1 reply