Draft C++14 includes both runtime-sized arrays and the std::dynarray
container. From what I can tell, the only real difference between the two is that std::dynarray
has an STL interface (e.g., begin
, end
, size
, etc.), while runtime-sized arrays do not. So why does C++14 need them both?
I understand that runtime-sized arrays are part of the core language, while std::dynarray
is part of the standard library, but the proposal for std::dynarray
makes clear that the authors expect compilers, in many cases, to offer special support for std::dynarray
so that it can be as efficient as possible, i.e., as efficient as a runtime-sized array. As such, the language/library distinction seems somewhat artificial.
So, again, why does C++14 need both runtime-sized arrays and std::dynarray
? And given that std::dynarray
has a richer (STLified) interface, why not just drop runtime-sized arrays, assuming that std::dynarray
can be implemented with equal runtime efficiency?
Clarification
When I talk about "runtime-sized arrays," I'm referring to a new C++14 core language feature that's described in N3639, not to traditional C arrays or VLAs or anything in C++11.
std::vector
? If so, the difference is mainly that withstd::dynarray
you ensure that there will be no resize (and therefore reallocations) during the life that object; therefore you can have stronger guaranties on the memory used by thedynarray
that you can't withvector
. – Endometriosisstd::array
vs. C-static-arrays. – Endometriosisstd::unique_ptr<T[]>
, but that one lacks iterators. That said, the difference is not very big. Variable-length arrays on the other hand are something completely different. – Goerdynarray
class will probably use runtime-sized arrays (when feasible). – Arithmeticstd::dynarray
was removed from the C++14 standard. See commentCH 2
In the official status. If you need this functionality, please use Boost. – Pannonia