To improve efficiency of std::vector<T>, it's underlying array needs to be pre-allocated and sometimes re-allocated. That, however, requires the creation and later moving of objects of type T with a copy ctor or move ctor.
The problem that I am having is that T cannot be copied or moved because it contains objects that cannot be copied or moved (such as atomic and mutex). (And, yes, I am implementing a simple thread pool.)
I would like to avoid using pointers because:
- I do not need a level of indirection and so I do not want one.
- (Pointers are less efficient and increase complexity. Using pointers increases memory fragmentation and decreases data locality which can (but not necessarily must) cause a noticeable performance impact. Not so important, but still worth consideration.)
Is there a way to avoid a level of indirection here?
UPDATE: I fixed some incorrect assumptions and re-phrased the question, based on feedback in comments and answers.