-
-
Notifications
You must be signed in to change notification settings - Fork 421
Fix - core.stdcpp.vector.vector does not implement opEquals #3255
Conversation
|
Thanks for your pull request, @n8sh! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "stable + druntime#3255" |
| @@ -114,6 +114,17 @@ extern(D): | |||
| /// | |||
| void append(T[] array) { insert(length, array); } | |||
|
|
|||
| /// Performs elementwise equality check. | |||
| bool opEquals(this This, That)(auto ref That rhs) | |||
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.
The complicated signature is because opEquals might or might not be callable with a const vector!T for any particular T.
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.
Is this definitely the best way to express this comparison?
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.
Not definitely.
|
|
||
| /// Hash to allow `vector`s to be used as keys for built-in associative arrays. | ||
| /// **The result will generally not be the same as C++ `std::hash<std::vector<T>>`.** | ||
| size_t toHash() const { return .hashOf(as_array); } |
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.
toHash on the other hand needs to be a non-template const function or else it will be ignored by the compiler for the purpose of determining if a particular struct has a non-default hash code.
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.
Please leave an obvious TODO that we should use std::hash in the future when it's written?
| if (is(immutable That == immutable vector)) { return as_array == rhs.as_array; } | ||
|
|
||
| /// Performs lexicographical comparison. | ||
| static if (is(typeof((ref T a, ref T b) => a < b))) |
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.
The static if is so __traits(hasMember, vector!T, "opCmp") will be false for vectors that do not support comparison.
|
@TurkeyMan review this please. |
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.
LGTM
No description provided.