In C ++, before C ++ 11, the displayed type std::map must be both constructive by default and copied constructive when operator[] called. However, boost::mutex explicitly designed so that it is not available for copying, since it is generally unclear what the semantics of copying the mutex should be. Due to the fact that boost::mutex not copied, the insertion of such a value using pointCloudsMutexes_[index] not performed.
The best workaround is to use some general pointer to boost::mutex as the display type, for example:
#include <boost/smart_ptr/shared_ptr.hpp> #include <boost/thread/mutex.hpp> #include <map> struct MyMutexWrapper { MyMutexWrapper() : ptr(new boost::mutex()) {} void lock() { ptr->lock(); } void unlock() { ptr->unlock(); } boost::shared_ptr<boost::mutex> ptr; }; int main() { int const index = 42; std::map<int, MyMutexWrapper> pm; pm[index].lock(); }
PS: C ++ 11 removed the requirement for the display type to be available for copy.
source share