lundi 3 octobre 2016

Custom vector doesn't support unique_ptr

So I am using a custom vector container from: http://ift.tt/2cNOnLI

and I am trying to create a vector of unique_ptr's pointing to a custom Class object.

It used to fail with:

error: object of type 'std::__1::unique_ptr std::__1::default_delete>' cannot be assigned because its copy assignment operator is implicitly deleted

I fixed it by adding the following code to vector.h:

void push_back(T&& val)
    {
        resize(m_size + 1);
        m_container[m_size - 1] = std::move(val);
    }

Now, the problem is, I am unable to iterate over this vector and other functions like swap are failing:

no matching function for call to 'swap'
        swap(*__x4, *__x5);
candidate template ignored: could not match 'tuple' against 'unique_ptr'
swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)

I need some guidance on how to fix these issues.

Aucun commentaire:

Enregistrer un commentaire