I have an issue:
When I am trying to move data from (vector with unique_ptr) to (list with unique_ptr) by std::copy algorithm is sucesfully compliles but then crushes in running! Here is a code:
std::vector<std::unique_ptr<std::string>> vecUPTRstring;
std::unique_ptr<std::string> ptrStringArr1(new std::string("qwe"));
std::unique_ptr<std::string> ptrStringArr2(new std::string("asd"));
vecUPTRstring.push_back(std::move(ptrStringArr1));
vecUPTRstring.push_back(std::move(ptrStringArr2));
std::list<std::unique_ptr<std::string>> listUPTRstring;
std::copy(std::make_move_iterator(vecUPTRstring.begin()),
std::make_move_iterator(vecUPTRstring.end()),
std::make_move_iterator(listUPTRstring.begin())
);
for (auto& var : listUPTRstring)
{
cout << "list value = " << var << endl;
}
The crash error is:
Expression: cannot dereference end list iterator
I have checked different ways to fix it and read some articles including this one, but I still need help with solving this problem.