3 ms·
I am not sure what you mean, you can definitely have e.g. an std::variant<int, std::string, bool> Which is a sum of those three types.
by sebtron 8mo ago
I am not sure what you mean, you can definitely have e.g. an
std::variant<int, std::string, bool>
Which is a sum of those three types.
- maleldil 8mo agoSee the first IpAddr example here[1], where you have separate variants, both with string representations. You can't do this with std::variant. You have to use separate types. [1] https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html
- sebtron 8mo agoI see what you mean now, thanks. To reproduce that example with std::variant I would need some kind of strong type alias, which as far as I know is missing from C++; so the only feasible way to do that would be wrapping the string in another class or struct.