This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not following this code. What does an explicit cast to a
superreference do? This needs an explanatory comment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From internal change:
This code says "define < comparison of encodable values as the < comparison of the underlying variant". (I've added a comment saying this)
The cast is needed because
lhs < rhswould just recursively call theoperator<we're trying to define here. (I wouldn't normally add a comment to this, feel free to suggest one)The high level idea is: expose an
operator<directly on EncodableType so thatvector<EncodableType> < vector<EncodableType>will delegate to that. Currently such comparisons fail to compile, for reasons that are pretty obscure.My best understanding is that variant's/vector's
operator<=>do not work properly when you inherit from variant/vector, and this is not a bug in libc++ but is specified in C++20. (I would further guess: this is not specifically intended, but an interaction of many factors and backwards-compat for code that inherits from stdlib classes is not a high priority.operator<=>is an outlier in that it breaks more existing code than most language changes).In any case, most of this is out of our hands: the new compiler rejects this code, it appears to be correct in doing so, I don't have a simple intuitive explanation why. Happy to add whatever comments you like though, please suggest some text.