4 ms·
- Traits: C++ concepts are on their way - there is even a working implementation in a gcc branch. Rust traits and C++ concepts are not the same thing at all.
by humanrebar 12y ago
- Traits: C++ concepts are on their way - there
is even a working implementation in a gcc branch.
Rust traits and C++ concepts are not the same thing at all. C++ concepts are sort of like template parameters with better (not complete) type checking. Rust traits are closer to interface declarations. Though it's really hard to do a description of either justice in an HN comment.
The rest of your bullet points are fair, if a bit optimistic. I don't see all the features you listed making it into C++ 2020. But I'm hopeful that many of them will be, especially sane libraries for extremely common problems like ASIO.
- tomjakubowski 12y agoThe closest comparison that comes to mind for Rust traits is Haskell type classes, except for some (important!) implementation details like Rust's static monomorphization. You even get something similar to existential types with trait objects.
- seabee 12y agoDescribing what they are may be too hard for a HN comment, but what they achieve is easier. Traits are the way Rust supports both dynamic dispatch and static dispatch in polymorphic functions. C++ supports both kinds of dispatch too, but the means to achieve it are not the same across all scenarios. If you want to go from one to the other, you'll probably have to rewrite your code or create wrapper classes in C++. In Rust, you accept a &trait instead of constraining a generic type. C++ handles static dispatch through implicit template interfaces today, in the future by concept maps (but you can implement an ersatz version of it today, described in a blog post I wrote on this very topic[1]). Dynamic dispatch is always through your class's vtable. [1] http://chrisbranch.co.uk/2015/02/make-your-c-interfaces-trait-forward/ http://chrisbranch.co.uk/2015/02/make-your-c-interfaces-trai...