相关疑难解决方法(0)

如何有效清除std :: queue?

我正在使用std :: queue来实现JobQueue类.(基本上这个类以FIFO方式处理每个作业).在一种情况下,我想一次性清除队列(从队列中删除所有作业).我没有看到std :: queue类中有任何明确的方法.

如何有效地为JobQueue类实现clear方法?

我有一个简单的循环弹出解决方案,但我正在寻找更好的方法.

//Clears the job queue
void JobQueue ::clearJobs()
 {
  // I want to avoid pop in a loop
    while (!m_Queue.empty())
    {
        m_Queue.pop();
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ queue stl

159
推荐指数
6
解决办法
13万
查看次数

标签 统计

c++ ×1

queue ×1

stl ×1