Hacker News new | ask | show | jobs
by tatterdemalion 3298 days ago
> Go also has zero-sized types (struct{}), so I wonder if this is also possible?

No. It specifically uses Rust's generics system, and the fact that generics are monomorphized at compile time, whereas Go interfaces are not.

C++ templates can be used in similar ways.

1 comments

Yes, but differently; C/C++ explicitly prohibit zero-sized types due to object identity.
To clarify: C says it's UB, C++ rounds up to 1.