Many classes in the c++ standard library now have move constructors, for example –
thread::thread(thread&& t)
But it appears that std::mutex does not. I understand that they can’t be copied, but it seems to make sense to be able to return one from a “make_mutex” function for example. (Not saying it’s useful, just that it makes sense)
Is there any reason why std::mutex doesn’t have a move constructor?
Well… mainly because I don’t think they should move. Literally.
In some OS-es a mutex might be modeled as a handle (so you could copy them) but IIRC a pthreads mutex is manipulated in-place. If you are going to relocate that, any threadsafety is going fly right out of the window (how would the other threads know that the mutex had just changed it’s memory address…)?