Stupid question but does this assumption always hold?
ptr to variant (class object) == ptr to variant alternative
Compare this, in which case it seems to be true:
#include <cstdio>
#include <variant>
using val = std::variant<std::monostate, int, bool, struct some_struct>;
struct some_struct
{
void print_ptr() {
printf("pointer to contents of variant A = %p\n", this);
}
};
int main()
{
val A = some_struct{};
printf("pointer to variant A = %p\n", &A);
std::get<some_struct>(A).print_ptr();
}
Yields
pointer to variant A = 0x7ffde4003818
pointer to contents of variant A = 0x7ffde4003818
But I can also imagine an implementation where the index variable is put before the union, which means that the union's address will start 1/2/4/8 bytes later.