C++ Dynamically assign std::map comparator

前端 未结 3 654
傲寒
傲寒 2021-01-16 09:40

So I have two classes containing std::map members with effectively identical functionality except that the ordering of one map is std::less and the other std::greater.

3条回答
  •  悲&欢浪女
    2021-01-16 10:18

    No. The comparison function is used to generate the actual data structure -- changing the comparison function would require rebuilding the structure from scratch.

    That said, if all you want to do is iterate the structure in reverse order, map is a reversible container, so you can just loop over the structure normally using the reverse iterators.

提交回复
热议问题