c++ - 如何 spsc_queue.pop() 这个结构?

标签 c++ boost struct queue lock-free

我正在尝试 spsc_queue.pop() 这个结构

enum action_type {
    SUBSCRIBE,
    UNSUBSCRIBE,
    MESSAGE
};

struct action {
    action() = default ;
    action(action_type t, connection_hdl h) : type(t), hdl(h) {}
    action(action_type t, server::message_ptr m) : type(t), msg(m) {}

    action_type type;
    websocketpp::connection_hdl hdl;
    server::message_ptr msg;
};

action a;
while(m_actions.pop(a)){
    ...

但是每当我测试

std::cout << "'" << a.type << "'" << std::endl;

'0' 被写入终端,但它应该只是action_type 的值之一。我读过 struct 的默认值是 0,但是为什么 spsc_queue.pop() 不能设置 a?

( boost::lockfree::spsc_queue )

最佳答案

SUBSCRIBE 的值 0。如果您想给 SUBSCRIBE 一个不同的值,您可以初始化枚举器,例如,使用 1:

enum action_type {
    SUBSCRIBE = 1,
    UNSUBSCRIBE,
    MESSAGE
};

其他枚举器将获得相应的下一个整数值。

关于c++ - 如何 spsc_queue.pop() 这个结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18797140/

相关文章:

c++ - 在 Windows7 64 位上使用 mingw 构建 Boost Python

c - 如何处理结构数组?

ios - 我如何组织这些数据?

c++ - 是否可以通过名称访问变量 UI 成员?

c++ - 我如何使用 QT3D 的 QMouseDevice 和 QMouseHandler

c++ - Boost 有向图 : comparing edges of a vertex

c++ - 理解 boost::variant

c++ - 使用并行模式库 (ppl.h)

c++ - 错误 C2059 : syntax error : ']' , 我无法弄清楚为什么这会出现在 C++ 中

c - strptime() 的问题