5
Rust to C++: Implementing The Question Mark Operator
(www.quarterstar.tech)
The center for all discussion and news regarding C++.
I didn't read your post. But note that
?depends on traits /type classes with associated types (Try,FromResidual, andFrom), and is often implemented for sum types (e.g.Result,Option) with at least two variants containingOutputandResidualtype values.The
FromResidualpart does value conversion for theResidual, 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.