创建固定大小队列的向量(提升循环队列)

Creating a vector of fixed sized queue (boost circular queue)

本文关键字:队列 循环 向量 创建      更新时间:2023-10-16

我有两个问题:1. 如何创建提升循环队列向量?2. 我应该如何表示前者的矢量大小?

我尝试了以下方法,但出现错误

// Boost Circular Queue -- This works fine
boost::circular_buffer<pkt> pkt_queue(3);
// Vector of queues - This has errors, i also wish to initialize the vector

std::vector<pkt_queue> per_port_pkt_queue;

你想要一个队列向量:

#include <boost/circular_buffer.hpp>
struct pkt { int data; };
int main() {
    // Boost Circular Queue -- This works fine
    typedef boost::circular_buffer<pkt> pkt_queue;
    pkt_queue a_queue(3);
    // Vector of queues - This has errors, i also wish to initialize the vector
    std::vector<pkt_queue> per_port_pkt_queue;
    per_port_pkt_queue.emplace_back(3);
    per_port_pkt_queue.emplace_back(3);
    per_port_pkt_queue.emplace_back(3);
    // or
    per_port_pkt_queue.assign(20, pkt_queue(3)); // twenty 3-element queues
}

科里鲁现场观看