treating memory returned by operator new(sizeof(T) * N) as an array
The issue of pointer arithmetic on allocated memory, as in your example: T* storage = static_cast<T*>(operator new(sizeof(T)*size)); // … T* p = storage + i; // precondition: 0 <= i < size new (p) T(element); being technically undefined behaviour has been known for a long time. It implies that std::vector can’t be implemented with well-defined … Read more