struct mykey {
int k;
mykey(int a) {
k=a;
}
bool operator<(const mykey& a)const {
return this->k>a.k;
}
};
template<typename t>
void replace_key(t& a,const typename t::key_type& oldk,
const typename t::key_type& newk) {
typename t::iterator pos=a.find(oldk);
typename t::value_type temp(newk,pos->second);
//不知道为啥定义这个temp,必须要初始化一下
a.erase(pos);
a.insert(typename t::value_type(newk,pos->second));
}
using p=pair<mykey,string>;
int main(int argv,char** argc) {
// std::ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
map<mykey,string,less<mykey>>dase {
{
3,"fsa"
},
{
4,"Dfas"
},
{
1,"o3r"
}
};
using ty=decltype(dase)::value_type;
replace_key(dase,3,100);
for(const auto ele:dase) {
cout<<ele.first.k<<" ";
}
return 0;
}