inserting object in a map without copying the object

Viewed 416

Is it possible to insert objects in a map, if the class of the object has disabled copy constructor and disabled copy operator? Is move semantics useful here?

#include <map>

class T {
public:
  T(int v): x(v) {};
private:
  T(const T &other); // disabled!
  T &operator=(const T &other); // disabled!
  int x;
};

int main() {
  std::map<int, T> m;
  m[42] = T(24);  // compilation error here!
}

edit I was not completely clear. The object is huge, so I don't want to make unnecessary copies of it. But I can modify the code of the class (maybe I need to implement move semantics?) and not the user code (the main function in the example).

3 Answers
Related