std :: queue中的就地对象构造<std :: tuple <xxx,std :: variant =“”>&gt;&gt;

时间:2017-02-16 10:43:24

标签: c++ tuples c++17 variant

我已经获得了带有std::queue的C ++ 17代码,其中std::tuple由指针和std::variant组成。代码如下:

struct EventA
{
    int a;
    float b;
    bool c;
};

struct EventB
{
    char x;
    unsigned int y;
};

class Window;
std::queue<std::tuple<Window *, std::variant<EventA, EventB>>> eventQueue;

使用std::variant就地建立队列中新元素的正确语法是什么?我尝试了很多语法而没有成功:

eventQueue.emplace(nullptr, -1024, 2.0f, true);
eventQueue.emplace(nullptr, 'a', 2048u);
eventQueue.emplace(nullptr, {-1024, 2.0f, true});
eventQueue.emplace(nullptr, {'a', 2048u});
eventQueue.emplace(nullptr, {std::in_place_type<EventA>, -1024, 2.0f, true});
eventQueue.emplace(nullptr, {std::in_place_type<EventB>, 'a', 2048u});
eventQueue.emplace(nullptr, std::foward_as_tuple(std::in_place_type<EventA>, -1024, 2.0f, true));
eventQueue.emplace(nullptr, std::foward_as_tuple(std::in_place_type<EventB>, 'a', 2048u));

0 个答案:

没有答案