Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eastl::vector move assignment operator and move constructor makes copies of elements? #55

Closed
xaxxon opened this issue Sep 18, 2016 · 2 comments

Comments

@xaxxon
Copy link

xaxxon commented Sep 18, 2016

I have a class which has a eastl::vector_multimap which is backed by a vector.

In my default move assignment operator for my class, I'm getting an error because my value types are move-only and eastl::vector is trying to copy them.

When I dig into the code, I get:


#if EASTL_MOVE_SEMANTICS_ENABLED
        template <typename K, typename T, typename C, typename A, typename RAC>
        inline typename vector_multimap<K, T, C, A, RAC>::this_type&
        vector_multimap<K, T, C, A, RAC>::operator=(this_type&& x)
        {
            base_type::operator=(eastl::move(x));
            eastl::swap(mValueCompare, x.mValueCompare);
            return *this;
        }
    #endif

then


    #if EASTL_MOVE_SEMANTICS_ENABLED
        template <typename T, typename Allocator>
        typename vector<T, Allocator>::this_type&
        vector<T, Allocator>::operator=(this_type&& x)
        {
            if(this != &x)
            {
                DoClearCapacity(); // To consider: Are we really required to clear here? x is going away soon and will clear itself in its dtor.
                swap(x);           // member swap handles the case that x has a different allocator than our allocator by doing a copy.   **** <===== THIS LINE
            }
            return *this; 
        }
    #endif

and eventually the stack trace gets to the point where it tries to make a copy of a unique_ptr and fails.

Why is it doing a copy instead of a move? Does this mean I cannot put move-only types in a vector?

@xaxxon xaxxon changed the title eastl::vector move assignment operator copies elements? eastl::vector move assignment operator and move constructor makes copies of elements? Sep 18, 2016
@xaxxon
Copy link
Author

xaxxon commented Sep 18, 2016

My specific issue is actually with eastl::multimap -- I'm doing more research into exactly what is going on.

@xaxxon xaxxon closed this as completed Sep 18, 2016
@xaxxon
Copy link
Author

xaxxon commented Sep 18, 2016

sorry.. buried reference type killing my default move assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant