4 ms·
I don't understand what's confusing with my example aha. Current situation: you have std::variant<int, whatever> x; you now want to discriminate on when
by jcelerier 2y ago
I don't understand what's confusing with my example aha.
Current situation: you have
std::variant<int, whatever> x;
you now want to discriminate on whenever x has been initialized explicitly or not, the two cases I posted:
// case 1
std::variant<int, whatever> x;
// case 2
std::variant<int, whatever> x = 0;
you have two options:
option A: does not needlessly increase sizeof, does not add indirection penalty upon access:
std::variant<std::monostate, int, whatever> x;
option B: needlessly increases sizeof, adds indirection penalty upon access (mostly relevant when compiling in debug mode without inlining if you still want to have a semblance of performance):
std::optional<std::variant<int, whatever>> x;