Consider:
class x {
std::array<int, 4> data_;
public:
x() /*no reference to data_ here*/ {}
};
Do the int
elements in data_
get zeroed, or is their value indeterminate?
By extension is that also true in this case:
class x {
std::variant<std::array<int, 4> /*other stuff here*/> data_;
public:
x() /*no reference to data here*/ {
data_.emplace<std::array<int, 4>>(/* no args */);
}
};
EDIT:
Extension: Is there a way I can get the desired behaviour from the variant (to not initialise the data).
If I pair the two example together I should be able to do:
struct no_init_array {
std::array<int, 4> array;
no_init_array() { } //does nothing
};
class x {
std::variant<no_init_array/*other stuff here*/> data_;
public:
x() /*no reference to data here*/ {
//call default ctor of no_init_array
//which does not init the std::array (I hope)
data_.emplace<no_init_array>(/* no args */);
}
};