...

/

When to Use std::variant

When to Use std::variant

This section explains some possible uses of std::variant

We'll cover the following...

Unless you’re doing some low-level stuff, possibly only with simple types, then unions might be a valid option [^noteGuide]. But for all other uses cases, where you need alternative types, std::variant is the way to go.

[^noteGuide]: See ...