mercredi 5 avril 2017

Moving list

Here is a complete program which reproduces my problem.

#include <vector>
#include <list>
#include <memory>
#include <utility>

int main()
{
    std::vector<std::list<std::unique_ptr<int>>> v;

    std::list<std::unique_ptr<int>> l;
    l.push_back(std::make_unique<int>(0));
    l.push_back(std::make_unique<int>(1));

    v.push_back(std::move(l)); // error
}

On the last line the compiler is complaining that the deleted copy constructor of std::unique_ptr is being referenced.

Since I'm moving the list into the vector, I assume no copy constructors will be called on the elements of the list.

Why is this happening? How would I go about fixing it?

I'm using MSVC 2017.

Aucun commentaire:

Enregistrer un commentaire