Daily bit(e) of C++ | std::monostate for std::variant
Daily bit(e) of C++ ♻️166, Representing an empty std::variant using std::monostate.
A default-constructed std::variant will always initialize with its first element as active.
This can be problematic because it requires the value construction of the first element, which can be costly, or the element may not even support value construction.
To avoid this issue and allow a semantically "empty" std::variant, we can use the special type std::monostate as the first argument of the std::variant.