Did you like how we did? Rate your experience!

4.5

satisfied

46 votes

How do you check if a variant has value at compile time ?

A std::variant almost always has a value when in scope. The only time it does not is when an exception is thrown during an assignment. The type of the contained value is not necessarily available at compile time, however. Since it implements a tagged union, the underlying type can change depending on the path through the code. If you need compile-time variant types, you are better off writing custom template code.

100%
Loading, please wait...