NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.45k stars 1.5k forks source link

Remove `comparator.hh` and use new C++ comparison operator defaulting #10832

Open Ericson2314 opened 4 months ago

Ericson2314 commented 4 months ago

See the docs on Default comparisons (since C++20) https://en.cppreference.com/w/cpp/language/default_comparisons

In short, one can now do

bool operator == (const MyType & h2) const = default;
auto operator <=> (const MyType & h2) const = default;

And this will work in the vast majority of cases.

This is better than the src/libutil/comparator.hh tricks we did before (predating C++ 20) of deriving those methods based on constructing a std::tuple with all the fields we wanted to compare on the fly.

Ericson2314 commented 4 months ago

After https://github.com/NixOS/nix/pull/10838, just have a couple of GENERATE_CMP left. However, the GENERATE_CMP_EXT We'll need to keep for now. That's OK, though.