mirror of
https://github.com/NixOS/nix
synced 2025-07-06 13:21:47 +02:00
Remove comparator.hh
and switch to <=>
in a bunch of places
Known behavior changes: - `MemorySourceAccessor`'s comparison operators no longer forget to compare the `SourceAccessor` base class. Progress on #10832 What remains for that issue is hopefully much easier!
This commit is contained in:
parent
2a95a2d780
commit
bc83b9dc1f
49 changed files with 300 additions and 271 deletions
|
@ -1,17 +1,8 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#define DECLARE_ONE_CMP(PRE, QUAL, COMPARATOR, MY_TYPE) \
|
||||
PRE bool QUAL operator COMPARATOR(const MY_TYPE & other) const;
|
||||
#define DECLARE_EQUAL(prefix, qualification, my_type) \
|
||||
DECLARE_ONE_CMP(prefix, qualification, ==, my_type)
|
||||
#define DECLARE_LEQ(prefix, qualification, my_type) \
|
||||
DECLARE_ONE_CMP(prefix, qualification, <, my_type)
|
||||
#define DECLARE_NEQ(prefix, qualification, my_type) \
|
||||
DECLARE_ONE_CMP(prefix, qualification, !=, my_type)
|
||||
|
||||
#define GENERATE_ONE_CMP(PRE, QUAL, COMPARATOR, MY_TYPE, ...) \
|
||||
PRE bool QUAL operator COMPARATOR(const MY_TYPE & other) const { \
|
||||
#define GENERATE_ONE_CMP(PRE, RET, QUAL, COMPARATOR, MY_TYPE, ...) \
|
||||
PRE RET QUAL operator COMPARATOR(const MY_TYPE & other) const noexcept { \
|
||||
__VA_OPT__(const MY_TYPE * me = this;) \
|
||||
auto fields1 = std::tie( __VA_ARGS__ ); \
|
||||
__VA_OPT__(me = &other;) \
|
||||
|
@ -19,30 +10,9 @@
|
|||
return fields1 COMPARATOR fields2; \
|
||||
}
|
||||
#define GENERATE_EQUAL(prefix, qualification, my_type, args...) \
|
||||
GENERATE_ONE_CMP(prefix, qualification, ==, my_type, args)
|
||||
#define GENERATE_LEQ(prefix, qualification, my_type, args...) \
|
||||
GENERATE_ONE_CMP(prefix, qualification, <, my_type, args)
|
||||
#define GENERATE_NEQ(prefix, qualification, my_type, args...) \
|
||||
GENERATE_ONE_CMP(prefix, qualification, !=, my_type, args)
|
||||
|
||||
/**
|
||||
* Declare comparison methods without defining them.
|
||||
*/
|
||||
#define DECLARE_CMP(my_type) \
|
||||
DECLARE_EQUAL(,,my_type) \
|
||||
DECLARE_LEQ(,,my_type) \
|
||||
DECLARE_NEQ(,,my_type)
|
||||
|
||||
/**
|
||||
* @param prefix This is for something before each declaration like
|
||||
* `template<classname Foo>`.
|
||||
*
|
||||
* @param my_type the type are defining operators for.
|
||||
*/
|
||||
#define DECLARE_CMP_EXT(prefix, qualification, my_type) \
|
||||
DECLARE_EQUAL(prefix, qualification, my_type) \
|
||||
DECLARE_LEQ(prefix, qualification, my_type) \
|
||||
DECLARE_NEQ(prefix, qualification, my_type)
|
||||
GENERATE_ONE_CMP(prefix, bool, qualification, ==, my_type, args)
|
||||
#define GENERATE_SPACESHIP(prefix, ret, qualification, my_type, args...) \
|
||||
GENERATE_ONE_CMP(prefix, ret, qualification, <=>, my_type, args)
|
||||
|
||||
/**
|
||||
* Awful hacky generation of the comparison operators by doing a lexicographic
|
||||
|
@ -55,15 +25,19 @@
|
|||
* will generate comparison operators semantically equivalent to:
|
||||
*
|
||||
* ```
|
||||
* bool operator<(const ClassName& other) {
|
||||
* return field1 < other.field1 && field2 < other.field2 && ...;
|
||||
* auto operator<=>(const ClassName& other) const noexcept {
|
||||
* if (auto cmp = field1 <=> other.field1; cmp != 0)
|
||||
* return cmp;
|
||||
* if (auto cmp = field2 <=> other.field2; cmp != 0)
|
||||
* return cmp;
|
||||
* ...
|
||||
* return 0;
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
#define GENERATE_CMP(args...) \
|
||||
GENERATE_EQUAL(,,args) \
|
||||
GENERATE_LEQ(,,args) \
|
||||
GENERATE_NEQ(,,args)
|
||||
GENERATE_SPACESHIP(,auto,,args)
|
||||
|
||||
/**
|
||||
* @param prefix This is for something before each declaration like
|
||||
|
@ -71,7 +45,6 @@
|
|||
*
|
||||
* @param my_type the type are defining operators for.
|
||||
*/
|
||||
#define GENERATE_CMP_EXT(prefix, my_type, args...) \
|
||||
#define GENERATE_CMP_EXT(prefix, ret, my_type, args...) \
|
||||
GENERATE_EQUAL(prefix, my_type ::, my_type, args) \
|
||||
GENERATE_LEQ(prefix, my_type ::, my_type, args) \
|
||||
GENERATE_NEQ(prefix, my_type ::, my_type, args)
|
||||
GENERATE_SPACESHIP(prefix, ret, my_type ::, my_type, args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue