|
|
|
|
|
by kmeisthax
6 days ago
|
|
No, the traits way of doing things is superior. C++ metaprogramming is dynamically typed with type errors raised at the instantiation site, resulting in inscrutable compile errors every time you call a generic function with the wrong thing and no obvious indication of what you're missing. In C++, if a template calls another template that adds two types, you get an error in the second function - which you might not even be aware of existing - that you need +. In Rust, if a function needs to add two types, it has to ask for Add, and that requirement bubbles up the call chain. Granted, I have personally worked with Rust generics that also knew how to throw inscrutable compile errors (looking at you, gtk-rs) but at least in that case it was still telling me that some type I'd provided was missing a trait and not that some arbitrary substitution failed three levels deep. |
|
It just doesn’t work for me in rust but the same thing works in zig and c++.