I'm looking for the best-practice of dealing with non-copyable objects.
I have a mutex class, that obviously should not be copyable. I added a private copy constructor to enforce that.
That broke the code - some places simply needed to be fixed, but I have a generic problem where a class, using the mutex either as a data member, or by inheritance, is being inserted into a container.
This is usually happening during the container initialization, so the mutex is not initialized yet, and is therefore ok, but without a copy constructor it does not work. Changing the containers to contain pointers is not acceptable.
Any advise?
Using c++11 on Ubuntu 14.04 (which includes emplace_back), I've gotten this to work.
I found that emplace_back worked fine, but erase (and probably insert) didn't work because, when the vector was shuffling the elements along to fill in the gap, it mas using:
I found the trick was allowing move assignment in my resource class:
This is my inotify_watch class, which can live in a std::vector: