pair 与其他容器一起使用

1.pair对作为map的关键字key

unordered_map<pair<int,int>,int> um;

um.count((d[0],d[1]));#错
um.count({d[0],d[1]});#错

以上两种方式报以下错误:

 

不能调用已经隐式删除的构造函数。用括号和花括号都不行。

尝试显式地构造

auto p1=make_pair(d[0],d[1]);
um.count(p1);#错

搜索之后https://blog.csdn.net/sinat_35261315/article/details/76473867,C++中没有提供pair作为map的关键字!!!

如果要这么做的话,需要添加hash函数。没太看明白。

 

posted @ 2021-01-27 16:53  lypbendlf  阅读(69)  评论(0编辑  收藏  举报