|
|
|
|
|
by fluffy87
2056 days ago
|
|
C++ templates are „untyped“ or very „weakly“ typed at the kindest, while Rust generics are „strongly“ typed. That’s the main difference in these languages features. Saying that Rust generics are „weaker“ than C++ templates is technically incorrect, since they are actuall „stronger“. Using these terms to mean something else is definitely „weird“. |
|
Can you provide your definition of strongly typed?
According to my understanding, C++ templates are evaluated at compile time, and the resulting instance has to qualify all the static type checks of standard C++. The deduced types is always checked, and if there is no substitution fullfill the type check is found, it raises a compile error.
The errors are super ugly, as there are no type constraints for template parameters, but funnily enough the template errors in C++ reminded me of playing around with Haskell without using function declarations. I would find it odd to call Haskell though untyped or weakly typed because of that.