Id like to ask, is safe having a variant like this?
struct A
{
unique_ptr<T> anything;
};
struct B
{
int x = 0;
int y = 0;
};
variant<A, B> myVar;
myVar = ... A object;
myVar = ... B object;
myVar = ... another A object;
Would the std::unique_ptr destructor be invoked for all compilers? The idea would be to create an std::array of variant<A, B> to use it in a FIFO. It seems working fine here in Visual Studio, but I ask because I read this from cppreference.com/variant, and I'm not sure if I understood it fully:
As with unions, if a variant holds a value of some object type T, the object representation of T is allocated directly within the object representation of the variant itself. Variant is not allowed to allocate additional (dynamic) memory.