I have read some old posts on propagate_on_container_move_assignment to understand how it works but still not able to wrap my head around some of the finer points. As per my understanding, move constructors work in a simple manner ( move construct allocator along with any internal state) but move assignment operators need to handle when allocators can propagate.
This answer in the following question two links provide some background on how the allocator propagation work and why it is required
- Why does propagate_on_XXX_assignment not apply to constructors?
- Example usage of propagate_on_container_move_assignment
Copied from the above links -
The container move assignment operator must deal with three separate possibilities:
- propagate_on_container_move_assignment is true.
- propagate_on_container_move_assignment is false, and the allocators from the lhs and rhs compare equal.
- propagate_on_container_move_assignment is false, and the allocators from the lhs and rhs compare unequal.
I understand the first two, however, for the third case "propagate_on_container_move_assignment is false, and the allocators from the lhs and rhs compare unequal." I do not understand how is this not an issue for move constructor. In case 3 for move assignments, we end up copying data as we can not own the memory of rhs allocator. While during move construction, we assume we can always own the memory and just move construct the allocator along with the internal state. If this were possible in move constructor then couldn't we do similar in move assignment - move assign the allocator and move assign the internal state.
To me it looks like if case 3 is true for move assignment then that would mean our move constructors as implemented without the "propagate" checks would be ill-formed.
Please help me understand the concept. Best provide an example where for move assignment we go for 3rd case due to allocator not supporting propagation( there should be a valid reason for the allocator to not support pocma = std::true_type ) but move constructor works?
Thanks,