Ste*_*e M 12
你可以使用a boost::circular_buffer包裹std::queue,如下所示:
#include <queue>
#include <boost/circular_buffer.hpp>
typedef std::queue<my_type, boost::circular_buffer<my_type>> my_queue;
const int n = 3;
...
my_queue q(boost::circular_buffer<my_type>(n));
q.push(1);
q.push(2);
q.push(3);
q.push(4); // queue now contains 2,3,4
Run Code Online (Sandbox Code Playgroud)