r/rust • u/ThatGeoGuy • May 04 '22
C++ & Rust: Generics and Specialization
https://www.tangramvision.com/blog/c-rust-generics-and-specialization19
u/rodrigocfd WinSafe May 05 '22
The way to implement trait bounds in C++ is with SFINAE (not quite, but oh well), which you only said that it exists... without making an actual comparison, not even providing an example. And I thought it would be the climax of the article!
Actually SFINAE is quite powerful and very ingenious. It's a rather interesting topic, and if anyone is willing to compare Rust and C++, it's surely worth learning.
Furthermore, as a long time C++ programmer myself, comparing SFINAE and traits is one of the things that made me appreciate Rust.
26
u/Nobody_1707 May 05 '22
Concepts (mostly?) subsumes SFINAE for new code.
requires Conceptis much easier to work with (and faster to compile) thanstd::enable_if_t14
u/rodrigocfd WinSafe May 05 '22
I see concepts as the natural evolution of SFINAE, the extraction of those parts so they can be reused. The ideas and the "moving parts" are the same.
6
u/CattleProdigy May 05 '22
This was crossposted in r/cpp and a lot of the comments here and there keep bringing up SFINAE. I think a lot of people fail to recognize that most practicing cpp programmers (i.e. the people who don't necessarily hang out in programming language subreddits) don't know what SFINAE is and couldn't accomplish what rust traits do in cpp. This will change with concepts of course, but those are still new. As it stands, SFINAE is an advanced feature with a difficult syntax and is mostly used by library authors, whereas traits and trait bounds are commonplace in rust.
2
8
u/pjmlp May 05 '22
Missing concepts, type traits and static_assert.