Given this array declaration and initialization:
std::array<bool, 20> invalid_params{};
Can I assume that all the elements in the array will always be initialized to false, or is it better to do it explicitly?
Given this array declaration and initialization:
std::array<bool, 20> invalid_params{};
Can I assume that all the elements in the array will always be initialized to false, or is it better to do it explicitly?
It's guaranteed to be filled with false
values.
std::array
is an aggregate, hence it has no user-defined constructors, hence value-initializing it performs zero-initialization.
But if you remove {}
(turning it into default-initialization), the elements will be uninitialized.
Documentation says: "default initialization may result in indeterminate values for non-class T". So, it seems that you can not assume that it will be initialized.