A more general solution to the problem would have been an inplace_allocator -- which requires a different API than allocator -- which could be applied to every container (standard or not).
This wouldn't fix anything. inplace_vector stores its data locally within the structure itself, while vector stores it through a pointer. You can't get around this, you need a different type who's designed to offer storage inside the vector. Allocator doesn't fix this, where is it gonna allocate to?
edit: I guess the allocator type itself has the storage? I didn't think about this but I guess this could actually work, but you still would need to fix all the requirements around resizing and whatnot
You're absolutely correct that std::allocator doesn't fit the bill...
... which is exactly why I advocate for a whole different API.
And yes, this would involve in-depth changes to anything taking this new API as they would no longer be able to take pointers, but would instead need to use "handles" of some sort, which would have some way to resolve into pointers when needed, and some rules about how long these pointers remain valid, etc...
I didn't say it was easy, I said it was generic :)
And yes, this would involve in-depth changes to anything taking this new API as they would no longer be able to take pointers, but would instead need to use "handles" of some sort, which would have some way to resolve into pointers when needed, and some rules about how long these pointers remain valid, etc...
I don't think you'd need to change the allocator API, you'd just provide an allocator type that just has its storage internally as part of the allocator. You could do some shit like this
1
u/Raknarg 18h ago
This wouldn't fix anything. inplace_vector stores its data locally within the structure itself, while vector stores it through a pointer. You can't get around this, you need a different type who's designed to offer storage inside the vector. Allocator doesn't fix this, where is it gonna allocate to?
edit: I guess the allocator type itself has the storage? I didn't think about this but I guess this could actually work, but you still would need to fix all the requirements around resizing and whatnot