To sort an STL container with std::sort(), the custom comparator used must satisfy the Compare named requirement. Specifically,
comp(a, b): Establishes strict weak ordering relation with the following properties:
- For all a, comp(a,a)==false
When sorting by whole values descending (specifically, sortBy: -1), we do the following negation:
if (useWholeValue) { const bool ascending = ValueComparator(collator).getLessThan()(lhs, rhs); const bool reversed = (sortPattern.firstElement().number() < 0); return (reversed ? !ascending : ascending);
Simply negating ascending is not correct, because when comparing two equal values, getLessThan() should return false for both.
This logic error triggers a fatal assertion on Windows debug builds, because the MSVC STL implementation checks for the validity of the comparator.