|
|
|
|
|
by forrestthewoods
243 days ago
|
|
I will boldly state that std::variant makes all code worse and it is always better to not use it. I love sum types in Rust. They’re great. This stuff exists solely to add ergonomics. If it’s not ergonomic it’s just making your code worse! std::variant is fundamentally broken because it uses types as its discriminant. Want a variant with two ints that represent two things? Fuck you, you can’t. Rust enums of course can do this. std::visit is an abomination. As is the template overloaded bullshit you have to copy paste into projects. And of course the error messages when you get when it’s wrong are atrocious even by C++ standards. No. std::variant is awful and you should simply never use it. This could change in 2040 when you can use C++32. But for now just avoid it. |
|
This is false, I also find that in general you have a tendency to make false claims about C++ in most of your posts about it. I would suggest you check out a resource like https://en.cppreference.com/ just as a sanity check before you make claims about the language in the future, and also because it's a very good resource for learning the ins and outs of the language.
As for your claim, std::variant supports index based discrimination similar to std::tuple, so you can absolutely have a std::variant<int, int>, and access the second int along the lines of:
This is all documented with examples:https://en.cppreference.com/w/cpp/utility/variant/get.html