std ::不可移动对象的地图

时间:2016-10-14 19:11:12

标签: c++11 std stdmap moveabletype

与我之前的问题相关: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.
}

0 个答案:

没有答案