I am trying to create a structure and insert that a map as following:
struct Queue_ctx {
std::mutex qu_mutex;
std::condition_variable qu_cv;
std::queue<std::vector<std::byte>> qu;
};
std::map<std::string, Queue_ctx> incoming_q_map;
Queue_ctx qctx;
std::vector<std::byte> vect(100);
qctx.qu.push(vect);
incoming_q_map.emplace("actor", qctx);
But I get the following error :
error C2660: 'std::pair<const std::string,main::Queue_ctx>::pair': function does not take 2 arguments
message : see declaration of 'std::pair<const std::string,main::Queue_ctx>::pair'
message : see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,const char(&)[6],main::Queue_ctx&>(_Alloc &,_Objty *const ,const char (&)[6],main::Queue_ctx &)' being compiled
with
[
_Alloc=std::allocator<std::_Tree_node<std::pair<const std::string,main::Queue_ctx>,std::_Default_allocator_traits<std::allocator<std::pair<const std::string,main::Queue_ctx>>>::void_pointer>>,
_Ty=std::pair<const std::string,main::Queue_ctx>,
_Objty=std::pair<const std::string,main::Queue_ctx>
]
AFAIU, emplace constructs the element inplace. if that is true then why compiler is trying to create pair to emplace? I see that the syntax of pair synthesized by the compiler is odd that's why it complains. But why does that happen and what can I do to fix this problem ?
I tried to pass make_pair()
explicitly but that did not help.
If I comment the qu_mutex
and qu_cv
then I am able to do emplace. What does error has to do with these two members? Isn't the case that default consutructor initializing the members of struct ?
I know copy/assignment/move constructors are deleted by the compiler.