2 ms·
Three questions: 1. what is the technical difference between template and generics? 2. how do we know that what Rust has are generics? 3. considering that the
by gnuvince 12y ago
Three questions:
1. what is the technical difference between template and generics?
2. how do we know that what Rust has are generics?
3. considering that the Rust type system was recently demonstrated to be Turing-complete, how can it be less powerful than C++'s?
- Matthias247 12y agoI'm not the person who can give an exact definition, but imho generics are more related to the type system (you can have types that refer to other types) whereas C++ templates can produce more or less arbitrary code. E.g. the field of template metaprogramming in C++ is not possible with generics. I'm personally not convinced that the extra possiblities and extra complexity of C++ templates vs. a good generics implementation in other languages is worth it, but I just wanted to highlight that the comparison is not fair. And hopefully we will get better error messages with C++ concepts, which will probably compare better to Rusts generics and kinds.
- chadzawistowski 12y agoTangential, but I'd like to point out that you can achieve compile-time metaprogramming much more easily in D, which provides the entire language during compilation [1]. I find this to be much more straightforward than arcane uses of templates such as SFINAE [2]. [1] http://en.wikipedia.org/wiki/Compile_time_function_execution#example http://en.wikipedia.org/wiki/Compile_time_function_execution... [2] http://en.m.wikipedia.org/wiki/Substitution_failure_is_not_an_error http://en.m.wikipedia.org/wiki/Substitution_failure_is_not_a...