Rust to C++: Implementing The Question Mark Operator

https://lemmy.world/post/44998067

Rust to C++: Implementing The Question Mark Operator - Lemmy.World

Lemmy

I didn’t read your post. But note that ? depends on traits /type classes with associated types (Try, FromResidual, and From), and is often implemented for sum types (e.g. Result, Option) with at least two variants containing Output and Residual type values.

The FromResidual part does value conversion for the Residual, which is how you e.g. get auto-converted error values matching the return Result value. These converted error values are often themselves contained in variants in an enum/sum Error type.

So neither an actual equivalent in C++ is possible, due to type system limitations/differences, nor whatever you tried to do is an apples-to-apples match, or even represents two fruits from the same basket.

Yeah I didn’t mean a one-to-one implementation in the pedantic sense; I meant more like how it would be implemented to address certain issues in C++ that I demonstrated at the beginning. Sorry if I wasn’t clear with the article’s name.