This is an archive of the discontinued LLVM Phabricator instance.

Refactor the POCXX allocator-handling into some common routines, and try them out in vector
ClosedPublic

Authored by mclow.lists on Jul 7 2015, 8:49 AM.

Details

Summary

Every container in libc++ has a set of routines for handling propagate_on_container_swap, propagate_on_container_move_assignment and propagate_on_container_copy_assignment. They're all basically identical.

Make generic versions of these routines in <memory>, and demonstrate their use in vector::swap.

Along the way, update the noexcept() conditions on vector::swap

Eventually, propagate this pattern across all the containers.

Diff Detail

Event Timeline

mclow.lists updated this revision to Diff 29184.Jul 7 2015, 8:49 AM
mclow.lists retitled this revision from to Refactor the POCXX allocator-handling into some common routines, and try them out in vector.
mclow.lists updated this object.
mclow.lists added a subscriber: cfe-commits.
EricWF edited edge metadata.Jul 7 2015, 1:27 PM

This looks like a good first step to removing this duplication. It would be nice if all of the relevant changes were in before 3.7.

The direction of the patch LGTM but I would like to understand the need for the noexcept specifications on __swap_allocator before I approve it.

include/memory
5551

Do we need these _NOEXCEPT decorators at all? I don't see where they are used or visible to the user.

5556

Shouldn't this call be __swap_allocator?

test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp
56

Use TEST_STD_VER.

test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp
57

Use TEST_STD_VER instead.

The direction of the patch LGTM but I would like to understand the need for the noexcept specifications on __swap_allocator before I approve it.

There are four cases:

  • If POCS is true, then in C++14 and beyond, swapping the allocators is required not to throw [allocator.requirements]/4
  • If POCS is true, in C++11 and before, we have to check if the swapping can throw
  • if POCS is false, we're not going to swap anything, so it can be noexcept.
include/memory
5551

We may not, but in an ideal world, I'd like to define vector::swaps noexcept in terms of the operations, rather than by fiat.

5556

Yes.

mclow.lists edited edge metadata.

Wow - this really grew in the telling (as Prof T would say).

I cut this down to just swap, and then reworked the swap for all the containers.
Turns out that our swaps were never noexcept for the unordered containers, map and set because we wrapped the comparison operators and the hashers, and the wrappers were not noexcept-swappable.

Lots of tests to make sure that they're right now.

mclow.lists accepted this revision.Jul 13 2015, 1:05 PM
mclow.lists added a reviewer: mclow.lists.

Committed as revision 242056.

This revision is now accepted and ready to land.Jul 13 2015, 1:05 PM
mclow.lists closed this revision.Jul 13 2015, 1:06 PM