Default constructor of boost variant initializes the first bounded type. How do I default initialize any member other than the first? One option is to simply assign a default constructed object of the right type. However, that does not work with some types like arrays. Without initialization boost::get
throws boost::bad_get
exception. So I can't do std::copy
on the array.
boost::variant<std:string, int[5]> v; // default initializes the string.
I need something like
initialize<int[5]>(v);
I also had compilation issues when using an array as the first bounded type. Clang reports error as follows:
object expression of non-scalar type 'int [5]' cannot be used in a pseudo-destructor expression
operand.~T();
Edit: I've the same question regarding boost.optional. Is there an API to default initialize an optional? I mean other than an assignment from a default initialized T.