2 ms·
Using macros to implement generics has the same problem that C++ templates have, which is described in the Go 2 generics proposal: it's difficult to provide cle
by djur 8y ago
Using macros to implement generics has the same problem that C++ templates have, which is described in the Go 2 generics proposal: it's difficult to provide clear error messages for developers in many cases. Functions parameterized on a single type are the easy problem to solve. Where things get thorny is when you parameterize on multiple types with various constraints and/or have some kind of interaction in the function body. The goal of the Go 2 generics contracts (and C++ concepts, Haskell typeclasses, Rust traits, etc.) is to make those expectations explicit.
- slavapestov 8y agoMacros and C++ templates are also incompatible with separate compilation which leads to increased compile times and binary bloat.