I have a queue. If it exceeds X size, when I push an element I want to remove the first element of the queue. (the last element that would get popped and the first element pushed in)
void ClientPlayerManager::queueTableMessage( const std::string& playerName, const std::string& message )
{
m_tableQ.push(std::make_pair(playerName,message));
if(m_tableQ.size() > m_maxTableMessages)
{
//m_tableQ.pop_back(); does not exist
}
}
Is there a way to do this with a std queue?
Thanks
You can use a
std::dequeinstead of astd::queue, which supportspush_front,push_back,pop_front, andpop_back. This also allows for random access throughout, but you can just ignore that and treat thedequelike a double-ended queue. (In fact,dequeis short for double-ended queue).Hope this helps!