4 ms·
As far as I've seen, std::variant's ergonomics isn't remotely competitive with rust sum types. C++ lacks the syntax.
by jstimpfle 2y ago
As far as I've seen, std::variant's ergonomics isn't remotely competitive with rust sum types. C++ lacks the syntax.
- flohofwoe 2y agoYet they're both conceptually the same old thing: tagged unions. In C++ everything is just more awkward since everything is bolted on as an afterthought in the stdlib but then lacking language syntax sugar to make its usage convenient. E.g. the (somewhat weird looking) equivalent to Rust's match is called 'visit' in C++: https://en.cppreference.com/w/cpp/utility/variant/visit2 https://en.cppreference.com/w/cpp/utility/variant/visit2
- zaphar 2y agoI can create tagged unions in literally any language not just C++ including Assembly. Rust having syntactic and compiler checked support for them as a foundational part of the language is a material difference in the design that differs fundamentally from C++. So the the point still stands.
- pjmlp 2y agoSyntax is on its way...
- lvass 2y agoSource?
- pjmlp 2y agoThere are at least three proposals in flight for C++26, if they reach an common agreement on time, or it has to be done by C++29, remains to be seen. Just search for the various revisions, https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/ https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/
- jstimpfle 2y agoI'm not even using Rust but I think you should stop hyping things that won't exist for years as if they were real and proven, like you've been doing a lot. I've had a quick look at one of the proposals behind the link and it's no comparison with the existing Rust way. Even std::variant itself is a crutch (being templatized by a list of types), not comparible with true algebraic datatypes.