Skip to content

Commit 4c70a52

Browse files
author
Vladimir 'virtul' Ivannikov
committed
fix swap of e.g .eastl::list<unique_ptr[]> with stateless/default allocator
...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
1 parent 7fadbf0 commit 4c70a52

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

include/EASTL/list.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,12 +1571,14 @@ namespace eastl
15711571
template <typename T, typename Allocator>
15721572
inline void list<T, Allocator>::swap(this_type& x)
15731573
{
1574-
if(internalAllocator() == x.internalAllocator()) // If allocators are equivalent...
1574+
if constexpr (is_empty_v<allocator_type>)
1575+
DoSwap(x);
1576+
else if (internalAllocator() == x.internalAllocator()) // If allocators are equivalent...
15751577
DoSwap(x);
15761578
else // else swap the contents.
15771579
{
1578-
const this_type temp(*this); // Can't call eastl::swap because that would
1579-
*this = x; // itself call this member swap function.
1580+
this_type temp(*this); // Can't call eastl::swap because that would
1581+
*this = x; // itself call this member swap function.
15801582
x = temp;
15811583
}
15821584
}

0 commit comments

Comments
 (0)