std::map of non-movable objects

178 Views Asked by At

Related to my previous question: Inserting an object having a non copyable field into an std::vector

It seems that I can have a map storing non-movable objects A only if A is default constructable.

Is there any way in C++11 to have a map store A if A is not default-constructable and non-movable?

#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

There are 0 best solutions below