Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Incorporating @jan-moeller's suggestion from #2.
There are a few caveats with this: I changed the
value_typetotypename Element::value_type. Theelementwrapper is used for custom comparisons inside aneternal::map, but the dereference operator returns the encapsulatedstd::pair. This means that STL algorithms will get thestd::pairand call its operators, e.g. when comparing. This may be fine for your use case, but it's different from theeternalsort order, which is based on the key exclusively and never on the value. This only matters when you useeternal::map/hash_mapas a multimap (i.e. with duplicate keys).An alternative could be to derive
elementfromstd::pairinstead of wrapping it. We can't usestd::pairdirectly because its comparison operators aren'tconstexprin C++11, theirstd::swapspecialization isn'tconstexpruntil C++20, and forelement_hash, we need a custom hashing comparator.