Well I'm using my own allocator for a vector that has fast run-time requirements to avoid calling new/delete. The problem is now that code like this is not compiling:
std::vector<char> x(1000);
std::vector<char,myalloc<char>> y(1000);
x = y;
This obviously occurs because the implementation of the std::vector's allocator is compile-time and changes the type. But code like the above should be allocator-independent.
For POD I can do memcpy of course, but is there any other method? I'm really close to implementing my own vector that would use a custom allocator dynamically, specified at run time and get rid of std::vector.
x.assign(y.begin(), y.end())or (C++11)x.assign(std::begin(y), std::end(y))should do it. A vector'soperator=()doesn't have overloads for that to work, regardless of what you think "should" be the case. If you really want a type which works that way, create a simplestruct/classtype - templated if required - that contains a vector (with whatever element type and allocator you use) and ensure itsoperator=()works as required.std::pmr::vectorinstead of juststd::vectoreverywhere and everything should "just work".