与我之前的问题相关:Inserting an object having a non copyable field into an std::vector
如果A
是默认构造的,我似乎可以有一个存储不可移动对象的地图A
。
如果A
不是默认构造且不可移动的,那么在C ++ 11中有没有办法建立地图存储A
?
#include <mutex>
#include <map>
#include <iostream>
class A {
public:
A(int i) {}
private:
std::mutex m;
};
int main() {
std::map<int, A> m;
//m.emplace(1, 3); //A is not movable => does wouldn't compile.
}