0

I am trying to study allocators, but I do not understand at all the uses of some allocator's aliases. In particular, I have already read in cppreference the consequences of the propagate_on_container_copy_assignment and propagate_on_container_move_assignment aliases on container's assignment operations:

propagate_on_container_copy_assignment

If (this member is derived from std::true_type and) the allocators of the source and the target containers do not compare equal, copy assignment has to deallocate the target's memory using the old allocator and then allocate it using the new allocator before copying the elements (and the allocator).

propagate_on_container_move_assignment

If this member is not provided or derived from std::false_type and the allocators of the source and the target containers do not compare equal, move assignment cannot take ownership of the source memory and must move-assign or move-construct the elements individually, resizing its own memory as needed.

This is the theory, but I do not understand which are the practical advantages that are provided.

In general, which are the reasons therefore the designer of a custom allocator should mark one or the other alias as true or false?

LoS
  • 448
  • 1
  • 3
  • 15
  • Related: [Example usage of propagate_on_container_move_assignment](https://stackoverflow.com/questions/27471053/example-usage-of-propagate-on-container-move-assignment) – davidhigh Mar 28 '23 at 16:39
  • @davidhigh, I have already read that post, but the answers do not satisfy my question at all. They explain what happens if it is true or false, but not why it should be declared true or false by the designer of the custom allocator. – LoS Mar 28 '23 at 16:41
  • What is unclear?! These options decide what happens when copying or moving between two containers. The allocator designers will then set the options they prefer, for whatever reason they might have. Are you asking what those reasons might be? The standard doesn't say. – BoP Mar 28 '23 at 17:44
  • Essentially, if a proposal is presented to the standard, the writers often present one or more examples where it is effectively useful. If the standard shows me these aliases, but do not specify just one example to demonstrate the advantages that justifies their existence, I can think they are simply theorical, then unuseful in real life. – LoS Mar 28 '23 at 19:35
  • 1
    [This paper](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0177r0) has some discussion. Unfortunately, it refers to another paper for further details, and that reference is a dead link. – Igor Tandetnik Mar 28 '23 at 23:26

0 Answers0