I've run into a problem with trying to move unique_ptrs between containers. I have a std::unordered_set called elements that contains a bunch of unique_ptrs. I want to move some of them to another unordered_set called subelements. How do I do this?
Here's my function:
void MeshContainer::MoveSubelements(){
int mesh_dim = MeshDimension();
for(auto el=elements.begin(); el!= elements.end(); ++el){
if((*el)->getDim() != mesh_dim){
subelements.insert(std::move(*el));
elements.erase(*el);
}
}
}
I get the following compiler error using the above code:
error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = MEl; _Dp = std::default_delete]’
I think the issue has to be with the copy constructor, but I thought that using std::move would resolve this.
Any ideas?
Thanks!