Skip to content
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

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

Open
Ericson2314 opened this issue Jun 3, 2024 · 1 comment
Open

Comments

@Ericson2314
Copy link
Member

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 added a commit to obsidiansystems/nix that referenced this issue Jun 3, 2024
Progress on NixOS#10832

This doesn't switch to auto-deriving the fields, but by defining `<=>`
we allow deriving `<=>` in downstream types where `Hash` is used.
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Jun 3, 2024
Known behavior changes:

- `MemorySourceAccessor`'s comparison operators no longer forget to
  compare the `SourceAccessor` base class.

Progress on NixOS#10832

What remains for that issue is hopefully much easier!
@Ericson2314
Copy link
Member Author

After #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.

Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Jun 3, 2024
Known behavior changes:

- `MemorySourceAccessor`'s comparison operators no longer forget to
  compare the `SourceAccessor` base class.

Progress on NixOS#10832

What remains for that issue is hopefully much easier!
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Jun 5, 2024
Known behavior changes:

- `MemorySourceAccessor`'s comparison operators no longer forget to
  compare the `SourceAccessor` base class.

Progress on NixOS#10832

What remains for that issue is hopefully much easier!
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Jun 13, 2024
Known behavior changes:

- `MemorySourceAccessor`'s comparison operators no longer forget to
  compare the `SourceAccessor` base class.

Progress on NixOS#10832

What remains for that issue is hopefully much easier!
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Jul 12, 2024
Known behavior changes:

- `MemorySourceAccessor`'s comparison operators no longer forget to
  compare the `SourceAccessor` base class.

Progress on NixOS#10832

What remains for that issue is hopefully much easier!
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Jul 12, 2024
Known behavior changes:

- `MemorySourceAccessor`'s comparison operators no longer forget to
  compare the `SourceAccessor` base class.

Progress on NixOS#10832

What remains for that issue is hopefully much easier!
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue Jul 12, 2024
Known behavior changes:

- `MemorySourceAccessor`'s comparison operators no longer forget to
  compare the `SourceAccessor` base class.

Progress on NixOS#10832

What remains for that issue is hopefully much easier!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant