Chaining of ordering predicates (e.g. for std::sort)

前端 未结 6 1825
说谎
说谎 2021-02-05 23:33

You can pass a function pointer, function object (or boost lambda) to std::sort to define a strict weak ordering of the elements of the container you want sorted.

Howeve

6条回答
  •  梦谈多话
    2021-02-06 00:32

    One conventional way to handle this is to sort in multiple passes and use a stable sort. Notice that std::sort is generally not stable. However, there’s std::stable_sort.

    That said, I would write a wrapper around functors that return a tristate (representing less, equals, greater).

提交回复
热议问题