template <typename InfoType>
class ObjPool {
public:
struct tag;
using size_type = unsigned;
using uid_type = IntWrapper<tag, size_type>;
uid_type add(InfoType&& newInfo) {
if (removedUids_.size()) {
uid_type reuse = removedUids_.back();
removedUids_.pop_back();
infos_[reuse] = newInfo; // This line
alive_[reuse] = true;
++size_;
return reuse;
}
else {
infos_.push_back(newInfo);
alive_.push_back(true);
++size_;
return uid_type(size_-1);
}
}
// Other code
};
The compiler generates error:
object of type 'Graph::NodeInfo' cannot be assigned because its copy assignment operator is implicitly deleted infos_[reuse] = newInfo;
I don't quite understand why? I defined a move assignment and expect this line to call the move version rather than the copy version.
Why is
infos_[reuse] = std::move(newInfo);
necessary here?
Compiled with clang with c++11.