features wish list: RAII; fixed size; bound check
https://stackoverflow.com/questions/16711697/is-there-any-use-for-unique-ptr-with-array compares vector ^ unique_ptr ^ std::array. Conclusion — Vector is more powerful, more versatile, more widely useful, less restrictive. std::array is
- – added to Boost then c++11
- – j4 std::array given vector? See http://stackoverflow.com/questions/4424579/stdvector-versus-stdarray-in-c
- ** fixed size, not growable. Pre-allocated.
- ** a simpler replacement for raw array.
- – j4 std::array given raw array? bound check?
All alternatives to std::array:
- vector and raw array
- boost::scoped_array and boost::shared_array — least quizzed.
The dtor in each data structure is a key feature if you want RAII:
- std::array — dtor probably destroys each element one by one. No q(delete) called since the elements could be on stack
- scoped_array — dtor calls delete, which is a key difference from scoped_ptr, according to my book [[beyond the c++ standard lib]]
- vector — dtor uses its allocator, which very likely calls delete since vector uses heap for the underlying growable array.
- unique_ptr<T> — yes as expected. This valgrind experiment shows the array-specialization uses delete, whereas the vanilla instance uses regular q(delete).