Sadly, "use a different allocator" does
not suffice to give you the in-place allocation strategy. This is because "
an allocator is a handle to a heap." You need some way for the allocator (which is a value type, and will be copied around quite a bit inside the internals of the STL) to point to the place-where-the-memory-should-come-from (which in this case is "inside
this specific polymorphic_value object, and not inside
that one (unless of course the polymorphic_value object is copied or moved, in which case we
do mean
that one)." The allocator model is not designed to work with allocators that are, themselves, heaps (and thus not value types).
Strongly recommend watching my talk linked above, even though it is 90 minutes.
It's quite possible to write an inplace_any,
inplace_function, inplace_unique_function, and so on, but you can't do it by just abusing the allocator model; that physically will not work — neither in theory, nor in practice on any mainstream implementation.