Can boost variant safely accept pointers to classes that are forward declared without any unintended implications such as using them with visitors?
class A;
class B;
typedef boost::variant<A*, B*> Variant;
class A {
public:
A() {}
};
class B {
public:
B() {}
};
I'd suggest using the builtin recursive element support for this exact purpose. It makes the (de)allocation(s) automatic and exception safe.
Here's a complete demo where
Bactually recursively contains avector<Variant>(which is 90% of the use-cases for forward-declared element types):Live On Coliru
Prints