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+[]中括號。