Skip to content

Commit

Permalink
fix swap of e.g .eastl::list<unique_ptr[]> with stateless/default all…
Browse files Browse the repository at this point in the history
…ocator

...or any other type that has deleted copy ctor.
Assume that if `allocator_type` is empty (*) then it's automatically
equal to passed instance and we can erase compile-time const assignment
branch, which is not compiles when T's copy ctor is deleted (e.g. unique_ptr)

(*) implicitly implied EASTL_NAME_ENABLED being off, since it's makes
allocator_type statefull
  • Loading branch information
Vladimir 'virtul' Ivannikov committed Feb 7, 2025
1 parent 7fadbf0 commit 4c70a52
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/EASTL/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -1571,12 +1571,14 @@ namespace eastl
template <typename T, typename Allocator>
inline void list<T, Allocator>::swap(this_type& x)
{
if(internalAllocator() == x.internalAllocator()) // If allocators are equivalent...
if constexpr (is_empty_v<allocator_type>)
DoSwap(x);
else if (internalAllocator() == x.internalAllocator()) // If allocators are equivalent...
DoSwap(x);
else // else swap the contents.
{
const this_type temp(*this); // Can't call eastl::swap because that would
*this = x; // itself call this member swap function.
this_type temp(*this); // Can't call eastl::swap because that would
*this = x; // itself call this member swap function.
x = temp;
}
}
Expand Down

0 comments on commit 4c70a52

Please sign in to comment.