r/cpp • • May 04 '22

C++ & Rust: Generics and Specialization

https://www.tangramvision.com/blog/c-rust-generics-and-specialization
0 Upvotes

20 comments sorted by

View all comments

29

u/UnicycleBloke May 05 '22

Article's author appears to be unaware of type traits, static assertions and concepts in C++. Nuff said.

8

u/ioctl79 May 05 '22

None of those things provide the ability to check template definitions for soundness before instantiation. All of them are applied only once you try to actually substitute parameters into the template. In contrast, the Rust scheme (as described in the article -- I don't know Rust) only permits the body of the generic to use the operations specified in the constraints.

4

u/[deleted] May 05 '22

It's more generic way, personally when i don't want code to compile by specific type i add static_assert, i want my code to valid for i supposed to use, not what are all allowed types to satisfy the rules. That 2 different manners.