Repository navigation
Move compressed_pair's elements from rvalues instead of copying them - #86
Merged
Merged
Conversation
compressed_pair only had constructors taking its elements by const reference, and cp_swap copied through a temporary. So unique_ptr, which stores its deleter in a compressed_pair, copied the deleter on construction from an rvalue deleter, on move construction and on swap: a move-only deleter didn't compile, although std supports one. A two-element forwarding constructor, constrained on the elements being constructible from the arguments, is added to compressed_pair and each of its layouts, and cp_swap moves. Lvalue arguments are still copied; the containers that store their allocator in a compressed_pair now move the default-constructed temporary allocator they pass in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
compressed_paironly had constructors taking its elements by const reference, andcp_swapcopied through a temporary.unique_ptrstores its deleter in acompressed_pair, so it copied the deleter on construction from an rvalue deleter, on move construction, and on swap: a move-only deleter didn't compile, although std supports one (MSVC STL's_Compressed_pairforwards its arguments). Found while adding the deleter constraints in #83; independent of it.compressed_pairand each of its six layouts (neither, first, second or both elements as empty bases, and the two same-type layouts) get a two-element forwarding constructor, constrained on each element being constructible from its argument. Rvalues are moved; lvalues still copy. The existing(const T1&, const T2&)constructor stays, so braced and converting arguments work as before.cp_swapmoves instead of copying.Effect on the containers: vector, list, slist, string and tuple_vector store their allocator in a
compressed_pair. Only list and slist pass rvalues to the two-element constructor: their default constructors pass a temporarybase_node_type()and a temporary default allocator, which are now moved instead of copied. Allocators passed as lvalues are copied as before.eastl::allocatordeclares a copy constructor and no move constructor, so moving it calls the same copy constructor, andbase_node_typeis two pointers: the default containers run the same code. A user allocator with its own move constructor is now moved from that temporary.Tests:
unique_ptr<int, MoveOnlyDeleter>constructed from an rvalue deleter, move constructed, move assigned and swapped, andunique_ptr<int[], MoveOnlyArrayDeleter>move constructed, each keeping the right deleter.On master both fail to compile (copy constructor and copy assignment of the move-only types in
compressed_pairandcp_swap).Verification: VS 2026 cl 14.51 and clang-cl 22, C++17 and latest, Debug and Release: all 8 EASTL suites pass, no new warnings compared with master.
🤖 Generated with Claude Code