My question is pretty straightforward, but to be more specific I want to quote 2 lines from Stroustrup11.
T[N] A fixed-size built-in array: N contiguous elements of type T;
no size() or other member functions array<T,N> A fixed-size array of N contiguous elements of type T;
like the built-in array, but with most problems solvedSo what is the difference the author is mentioning? And what problems are solved for std::array<T,N> ?
The principal differences are that std::array<T, N> doesn't decay to a pointer to the first element where T[N] would, and you can take a value copy of a std::array<T, N>.
std::array also offers some useful functions, such as lexicographical comparison operators.
But because N has to be a compile time evaluable constant expression, std::vector<T> is often the preferred choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With