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.
Incorporating @jan-moeller's suggestion from #2.
There are a few caveats with this: I changed the
value_type
totypename Element::value_type
. Theelement
wrapper is used for custom comparisons inside aneternal::map
, but the dereference operator returns the encapsulatedstd::pair
. This means that STL algorithms will get thestd::pair
and call its operators, e.g. when comparing. This may be fine for your use case, but it's different from theeternal
sort order, which is based on the key exclusively and never on the value. This only matters when you useeternal::map/hash_map
as a multimap (i.e. with duplicate keys).An alternative could be to derive
element
fromstd::pair
instead of wrapping it. We can't usestd::pair
directly because its comparison operators aren'tconstexpr
in C++11, theirstd::swap
specialization isn'tconstexpr
until C++20, and forelement_hash
, we need a custom hashing comparator.