Since you've deleted both copy and move constructors/assignment operators, the answer is: You can't make use of such a vector
in any reasonable way. Without copy or move as an option, you're at best able to pre-reserve
space once and emplace_back
into the vector
, but anything that might subsequently change the capacity, or in any way rearrange the elements, would be illegal (because it would implicitly involve use of move or copy operations).
As mentioned in the comments though, you can make a vector
of smart pointers, where only the smart pointer must be moved/copied, not the Res
instance it points to, and get a fully functional vector
. For example, with std::unique_ptr
, your class could be implemented as:
class ResourceCache{
....
const Res& GetRes(size_t index) {
return *resources_.at(index); // Can still provide const references at API level
}
std::vector<std::unique_ptr<Res>> resources_;
}
and you'd just use resources_.push_back(std::make_unique<Res>(...args to Res constructor...))
to create/insert elements into resources_
, rather than resources_.push_back(Res(...args to Res constructor...))
.