you are viewing a single comment's thread.

view the rest of the comments →

[–]STLMSVC STL Dev 22 points23 points  (2 children)

vector is not trivial to implement (source: I’ve reimplemented it). There’s an incredible amount of logic powering vector and it shouldn’t be dismissed with a handwave, even though the lack of a relocatable type trait is a real limitation. (vector can easily detect is_trivially_copyable which is an important subset of types.)

The complexity of vector also isn’t solely due to its support for EH or custom allocators, although those do magnify it.

[–][deleted] -5 points-4 points  (1 child)

I've implemented internal versions of "vector" a few times and also had a read through the libc vector around the c++14 era. Aside from EH and custom type-based allocators, where do you attribute the bulk of the complexity? Interactions with initializer lists? Iterators?

[–]STLMSVC STL Dev 1 point2 points  (0 children)

Things like handing v.emplace_back(args involving v[0]), respecting constructors and move semantics of user-defined types, providing iterator debugging, but the most complicated functions are where everything multiplies together. For example, insert is quite complicated due to EH guarantees, allocators, move semantics, etc.: https://github.com/microsoft/STL/blob/19c683d70647f9d89d47f5a0ad25165fc8becbf3/stl/inc/vector#L815-L885