You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
N4475 and a few related papers discuss the idea of generating the operators ==, !=, <, >, <= and >= be defaults for classes, with "usual" semantics (too long to explain here) and under some specific conditions.
As every paper discussing comparison, it might have an influence on sorting operations, but how? It seems that a generated operator< would perform a lexicographic comparison over every member of the class to compare, in declaration order. If every member of a class is taken into account, then a basic sort over the structure is stable under some conditions:
The comparison is a total order.
The type doesn't have equivalent elements (looking at you foating point numbers).
The iterators don't have observable side effects.
The copy/move operations on the type don't have observable side effects.
Provided the standard library adds type traits such as is_trivially_less_than_comparable to help identify such classes, it may be possible to make stable sorts use equivalent unstable sorts when they exist since the latter should be more performant. It relates to issue #21 but more work has to be done to identify when such a trick is usable and whether it is worth it.
The text was updated successfully, but these errors were encountered:
Default comparisons just got nuked from orbit during the Oulu meeting. If they ever come back, they will probably be opt-in and, even then, it is not guaranteed than any type traits might be proposed to detect them. We can safely close this issue for now, and maybe reopen it in a few years if needed.
N4475 and a few related papers discuss the idea of generating the operators
==
,!=
,<
,>
,<=
and>=
be defaults for classes, with "usual" semantics (too long to explain here) and under some specific conditions.As every paper discussing comparison, it might have an influence on sorting operations, but how? It seems that a generated
operator<
would perform a lexicographic comparison over every member of the class to compare, in declaration order. If every member of a class is taken into account, then a basic sort over the structure is stable under some conditions:Provided the standard library adds type traits such as
is_trivially_less_than_comparable
to help identify such classes, it may be possible to make stable sorts use equivalent unstable sorts when they exist since the latter should be more performant. It relates to issue #21 but more work has to be done to identify when such a trick is usable and whether it is worth it.The text was updated successfully, but these errors were encountered: