And last problem: this MUST compile
int main() {
std::variant<int, int> var;
std::get_if<int>(&var);
}
No comment on the first part, but this part is a complete non-starter. We do it this way because
std::variant<time_t, ptrdiff_t> var;
var = time();
if (ptrdiff_t *p = std::get_if<ptrdiff_t>(&var)) {
puts("the variant holds a ptrdiff_t");
}
This "MUST" either compile and Do The Right Thing (if time_t and ptrdiff_t are distinguishable types), or else noisily fail to compile (if they are the same type). What it absolutely must NOT do is silently compile and Do The Wrong Thing — i.e. permit us to accidentally treat a time as a pointer offset or vice versa.
–Arthur