Вопрос

I'm trying to spsc_queue.pop() this struct

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;
};

with

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

but whenever I test with

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

'0' is written to the terminal, but it should only be one of the values of action_type. I have read that the default value for a struct is 0, but why can't spsc_queue.pop() set a?

(boost::lockfree::spsc_queue)

Это было полезно?

Решение

The value of SUBSCRIBE is 0. If you want to give SUBSCRIBE a different value you can initialize the enumerator, e.g., with 1:

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

The other enumerators will get the respective next integer value.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top