Function swap


#include <include/EASTL/deque.h>

void swap(this_type &x)


// The reset_lose_memory function is a special extension function which unilaterally // resets the container to an empty state without freeing the memory of // the contained objects. This is useful for very quickly tearing down a // container built into scratch memory.

// Currently we are unable to get this reset_lose_memory operation to work correctly // as we haven't been able to find a good way to have a deque initialize // without allocating memory. We can lose the old memory, but DoInit // would necessarily do a ptrArray allocation. And this is not within // our definition of how reset_lose_memory works. base_type::DoInit(0);


Lines 2083-2108 in include/EASTL/deque.h. Line 390 in include/EASTL/deque.h.

template <typename T, typename Allocator, unsigned kDequeSubarraySize>
void deque<T, Allocator, kDequeSubarraySize>::swap(deque& x)
    if(mAllocator == x.mAllocator) // If allocators are equivalent...
    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.
        x     = temp;
    // NOTE(rparolin): The previous implementation required T to be copy-constructible in the fall-back case where
    // allocators with unique instances copied elements.  This was an unnecessary restriction and prevented the common
    // usage of deque with non-copyable types (eg. eastl::deque<non_copyable> or eastl::deque<unique_ptr>). 
    // The previous implementation violated the following requirements of deque::swap so the fall-back code has
    // been removed.  EASTL implicitly defines 'propagate_on_container_swap = false' therefore the fall-back case is
    // undefined behaviour.  We simply swap the contents and the allocator as that is the common expectation of
    // users and does not put the container into an invalid state since it can not free its memory via its current
    // allocator instance.

Add Discussion as Guest

Log in