0

I have a std::map<int, std::mutex> and want to add an element. Since std::mutex is not movable, I need to go for emplace, right?

I am familiar with the map.emplace(<key>, <constructorArgument>) syntax, but how does this work, when the constructor takes no arguments?

Minimal test code including stuff that does not work

#include <iostream>
#include <map>
#include <mutex>

int main()
{
    std::map<int, std::mutex> mm;
//    mm[3] = std::mutex();
//    mm.emplace(3, std::mutex());
//    mm.emplace(3, {});
//    mm.emplace(3, ());
//    mm.emplace(3);

    std::cout << mm.size() << " elements" << std::endl;
    return 0;
}
Simon Warta
  • 10,850
  • 5
  • 40
  • 78

0 Answers0