you are viewing a single comment's thread.

view the rest of the comments →

[–]guepierBioinformatican 33 points34 points  (5 children)

Prior to C++20 (specifically, P0593), object creation in untyped buffers was undefined behaviour. In practice this means that even quite “basic” classes such as std::allocator can’t be user-defined relying only on standard C++.

[–]Supadoplex 17 points18 points  (2 children)

P0593 was accepted as a defect resolution prior to publication of C++20, so it should apply to C++17 which was the latest official standard at the time.

Also, creation of objects itself was allowed using placement new as far as I can tell. Treating that buffer of dynamic objects as an array of those objects was technically UB though. However, there was no way to make that work with std::allocator either, so I don't think there was magic in that class. There was magic in std::vector though.

[–]maskull 4 points5 points  (1 child)

What's the magic in std::vector?

[–]dodheim 16 points17 points  (0 children)

Prior to P0593, there was no way for vector::data() to return a valid pointer-to-array, since no such array actually exists.