I have a class with private constructor (that my container class can access), deleted copy constructor, and default move constructor. How can I use it in a std::map?
class Item {
public:
Item(const Item&) = delete;
private:
friend class Storage;
Item(int value);
};
class Storage {
public:
void addItem(int key, int value) {
// what to put here?
}
private:
std::map<int, Item> items_;
};
Using emplace(key, Item(value)) doesn't work, because it tries to copy construct the item. Wrapping Item in std::move has the same effect. Using piecewise_construct doesn't work because the map (or pair) tries to use normal constructor, which is private.