C 11 vector::resize() Behavior with Standard and Boost Container Libraries
vector::resize() underwent an overhaul in C 11 to provide more granular control over element initialization. However, concerns have been raised regarding its behavior under both the standard library and Boost.Container in C 03 mode.
Standard Library
The vector::resize() function in the standard library prior to C 11 allows for element initialization by passing a value. However, in C 11, the function was split into two overloads: one for value initialization and one for initialization via copy.
Boost.Container
Boost.Container also provides three overloads of vector::resize(): value initialization, default initialization (a Boost-specific feature), and initialization via copy.
Observations
A recent test revealed that the resize() behavior in both the standard library and Boost.Container is inconsistent with expectations in C 03 mode. While resize() should ideally behave the same across all three tests (value, default, and copy initialization), the results show that only the test specifically requesting default initialization produces the desired output.
Conclusion
The discrepancy in behavior suggests that the vector::resize() interface change in C 11 may not have fully taken effect, as the added elements in the final resize() calls are still being initialized with zeros in the standard and Boost.Container tests without explicit default initialization. Further investigation is required to determine the reason for this behavior.
The above is the detailed content of How Does `vector::resize()` Behave Differently in C 03 with Standard and Boost Container Libraries?. For more information, please follow other related articles on the PHP Chinese website!