|
|
|
|
|
by volta83
1758 days ago
|
|
Rust traits are opt-in, C++ concepts are opt-out; you can think of C++ concepts as having a "blanket" implementation for all types, so you'd need to opt out using negative reasoning. For example, in C++, you can declare a trait: template <typename T>
struct totally_ordered : std::false_type {};
and opt-in implement it for some types, but not for floats.Then you can define a TotallyOrdered concept that requires the trait. The C++ standard library didn't do this, so if you happen to accidentally implement a type with an API that conforms to TotallyOrdered, then it becomes "accidentally" TotallyOrdered, which is a big footgun. |
|
If your Delicious concept mistakenly applies to my Desert, how do I as the author of the Desert tell C++ "No, no, when people ask if a Desert is Delicious tell them it isn't?".