-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide comparison operators for map/set/etc. instead of _Tree #1022
Conversation
This came up on libcxx-dev in the last couple of weeks because someone was working on spaceship: they don't, and no one noticed before. |
Does the standard wording allow them to be defined as hidden friends instead? My understanding is that this would lead to less compiler spew if it can't find an appropriate overload for comparison operators and a standard container is involved. |
While hidden friends would both improve compiler throughput and diagnostic quality, they would also break existing code in certain cases. Example:
(Inspired by an example reduced from LLVM by Barry Revzin on March 8, 2019.) |
Yes, I'm aware that the two approaches aren't functionally equivalent. I was just wondering if the standard allowed both (explicitly or via some loophole) or explicitly required a regular free function version. But I could have looked up that myself. Sorry for the noise. |
It was an excellent question, not noise at all! I would have guessed that the difference wasn't observable, if I hadn't seen the counterexample. (It is also sometimes very hard to find the Standardese that forbids users from doing things like taking the address of Standard Library member functions, etc.) |
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.
Yay @ahanamuk is soooo happy about these changes 😄
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.
What about _Hash?
@BillyONeal Excellent question. Fortunately, Here are the properly defined operators for Lines 465 to 475 in 550713e
Lines 755 to 765 in 550713e
Lines 319 to 329 in 550713e
Lines 581 to 591 in 550713e
|
Hmmm you might have asked me to add those before and that's the vague memory this ticked. Thanks! |
Fixes #215. I am not actually sure whether this is observable in C++20, but doing what the Standard depicts is generally a good idea, and will make it easier to develop and validate the spaceship operator changes.
Test coverage is provided by
std
:STL/tests/std/include/instantiate_containers_iterators_common.hpp
Lines 70 to 83 in 550713e
STL/tests/std/tests/VSO_0000000_instantiate_containers/test.cpp
Lines 442 to 446 in 550713e
and the
tr1
legacy test suite:STL/tests/tr1/tests/map/test.cpp
Lines 195 to 200 in 550713e
(Curiously, I was unable to find where
libcxx
tests the container comparisons, but I didn't search very intensively.)