You could implement it with realloc. The problem is it's not part of the interface the standard containers use, so they wouldn't be able to use it.
Printable View
You could implement it with realloc. The problem is it's not part of the interface the standard containers use, so they wouldn't be able to use it.
I have never in my life traced a performance problem to an expanding array that was implemented correctly. Whether copies are required or not. I think you're imagining problems that don't exist.
If an object is expensive to copy, then that object is probably rather large, and you ought to be storing pointers (preferably, smart pointers) instead of objects.
Yeah I think I made out like I care more than I actually do. My main concern has always been that rookie programmers use realloc incorrectly.
Sure it might be nice to have realloc available from the standard allocator in C++, but at the same time I think we're just fine without it. Those that do tend to use it are often likely to be prematurely optimising anyway.