Hacker News new | ask | show | jobs
by phire 874 days ago
The real std::array is static. But c doesn't really have any way to do static arrays, so c_std has decided to implement a dynamic array with an api similar to the std::array.

The documentation is correct regarding what c_std has actually implemented. And it's still useful, unlike vector the size is (dynamically) set once at construction and then enforced.

2 comments

Of course C can do static array:

    int array[N]; 
is one.
But not an abstract data structure that can be allocated on the stack.

(Your example can go on the stack. A struct with a final array member of unspecified size can work as an abstract data structure. But you can't have both at once.)

Well, std::array is meant to be a direct replacement for what jenadine mentioned, the C style of doing static arrays. I think under the hood it takes over the array initialization syntax as well (or array initialization of objects got added to the standard to support std::array?) and IIRC there are some functions that are simply unavailable to std::array because of its array based construction.

I don't remember exactly what but I have run into it before, I think the iterator implementation is a raw pointer and that breaks the interface expectations a bit?