DEV Community

Discussion on: What Does C++ Do That Rust Doesn't?

 
danielbsmith profile image
Daniel Smith

Isn't that just different placement of the error

I don't think this is completely true. It is at least simpler to constrain generic types more strictly than the current implementation requires in Rust. You may wish to add extra constraints on the type to give yourself implementation flexibility without needing to break callers. For example, if the current implementation only requires equality but I only want to accept types that implement ordering, that's pretty trivial in Rust. I would guess you could use some if 0 trick in C++ to use the operator but not impact the implementation, but that obscures intent at a minimum.

Thread Thread
 
danielbsmith profile image
Daniel Smith

Conversely, (stable) Rust does not have the equivalent of SFINAE. Specialization is available in nightly, which is pretty similar. I've seen this come up comparing Abseil Swiss Map and Hashbrown maps. The former will usually do the most efficient thing by default, but the latter requires the subtle RawEntry API to do things like lookup or insert without copying unless I'm actually inserting.