Monday, May 21, 2012

Is const_cast(iterator->second) safe?

I want to know if this code is safe and doesnt have any undefined behavior.



 QueueMap::const_iterator it = m_3playersQueue.find(s->m_GameCode);
if(it == m_3playersQueue.end())
{
std::deque<Session*> stack;
stack.push_back(s);

m_3playersQueue[s->m_GameCode] = stack;
return;
}

const_cast<std::deque<Session*>&>(it->second).push_back(s);

QueueMap is of type std::tr1::unordered_map< uint32, std::deque<Session*> >


Thanks





No comments:

Post a Comment