queue与pair

1.添加元素的方式

    queue<pair<int,int>> q;
    q.push({1,2});
q.push(make_pair(1,2)); q.emplace(
1,2);

上面三种方法是ok的,emplace会直接构造,而push需要显式地调用一下。

q.push((1,2));
//error: no matching function for call to 'std::queue<std::pair<int, int> >::push(int)'

上面的方法是错误的,不能隐式构造。下面也是:

q.push(1,2);
//error: no matching function for call to 'std::queue<std::pair<int, int> >::push(int, int)'

2.从queue中取pair 

auto [x, y] = Q.front();

auto+[]中括号。

原文地址:https://www.cnblogs.com/BlueBlueSea/p/14356854.html