std :: map change key_comp初始化后 [英] std::map change key_comp after initialization
问题描述
在创建和初始化std :: map之后,可以更改它的比较方法?
或者也许只有在它被创建后
It is possible to change the comparison method of a std::map after it has been created and initialized? Or maybe only after it has been created??
我想改变某个类的行为,该类包含一个我不能改变定义的地图。
I want to alter somehow the behavior of a class that contains a map that I cannot change the definition. I want to change it's comparison behavior maybe by passing another map.
推荐答案
也许有可能,这是未经测试的:
Maybe it is possible, this is untested:
- 定义您自己的自定义比较器,其内部具有指向实际执行比较函数的指针
- 通过(你必须使用这个比较器来键入地图。)
- 稍后(使用地图之前)设置真实的实现,如果你设置它之后,你不知道对内部结构的影响...
已经测试过,可以做到以上,但是如果树中有项目,更改比较功能可能是灾难性的...
Have tested, and it is possible to do the above, however changing the comparison function if there are items in the tree can be disastrous...
无论如何,这一切听起来太鱼腥....
Anyway - it all sounds too fishy....
这篇关于std :: map change key_comp初始化后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!