Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
comparator.hh File Reference
#include <tuple>

Go to the source code of this file.

Macros

#define DECLARE_ONE_CMP(PRE, QUAL, COMPARATOR, MY_TYPE)
#define DECLARE_EQUAL(prefix, qualification, my_type)
#define DECLARE_LEQ(prefix, qualification, my_type)
#define DECLARE_NEQ(prefix, qualification, my_type)
#define GENERATE_ONE_CMP(PRE, QUAL, COMPARATOR, MY_TYPE, ...)
#define GENERATE_EQUAL(prefix, qualification, my_type, args...)
#define GENERATE_LEQ(prefix, qualification, my_type, args...)
#define GENERATE_NEQ(prefix, qualification, my_type, args...)
#define DECLARE_CMP(my_type)
#define DECLARE_CMP_EXT(prefix, qualification, my_type)
#define GENERATE_CMP(args...)
#define GENERATE_CMP_EXT(prefix, my_type, args...)

Macro Definition Documentation

◆ DECLARE_CMP

#define DECLARE_CMP ( my_type)
Value:
DECLARE_EQUAL(,,my_type) \
DECLARE_LEQ(,,my_type) \
DECLARE_NEQ(,,my_type)

Declare comparison methods without defining them.

◆ DECLARE_CMP_EXT

#define DECLARE_CMP_EXT ( prefix,
qualification,
my_type )
Value:
DECLARE_EQUAL(prefix, qualification, my_type) \
DECLARE_LEQ(prefix, qualification, my_type) \
DECLARE_NEQ(prefix, qualification, my_type)
Parameters
prefixThis is for something before each declaration like template<classname Foo>.
my_typethe type are defining operators for.

◆ DECLARE_EQUAL

#define DECLARE_EQUAL ( prefix,
qualification,
my_type )
Value:
DECLARE_ONE_CMP(prefix, qualification, ==, my_type)

◆ DECLARE_LEQ

#define DECLARE_LEQ ( prefix,
qualification,
my_type )
Value:
DECLARE_ONE_CMP(prefix, qualification, <, my_type)

◆ DECLARE_NEQ

#define DECLARE_NEQ ( prefix,
qualification,
my_type )
Value:
DECLARE_ONE_CMP(prefix, qualification, !=, my_type)

◆ DECLARE_ONE_CMP

#define DECLARE_ONE_CMP ( PRE,
QUAL,
COMPARATOR,
MY_TYPE )
Value:
PRE bool QUAL operator COMPARATOR(const MY_TYPE & other) const;

◆ GENERATE_CMP

#define GENERATE_CMP ( args...)
Value:
GENERATE_EQUAL(,,args) \
GENERATE_LEQ(,,args) \
GENERATE_NEQ(,,args)

Awful hacky generation of the comparison operators by doing a lexicographic comparison between the choosen fields.

GENERATE_CMP(ClassName, me->field1, me->field2, ...)
#define GENERATE_CMP(args...)
Definition comparator.hh:65

will generate comparison operators semantically equivalent to:

bool operator<(const ClassName& other) {
return field1 < other.field1 && field2 < other.field2 && ...;
}

◆ GENERATE_CMP_EXT

#define GENERATE_CMP_EXT ( prefix,
my_type,
args... )
Value:
GENERATE_EQUAL(prefix, my_type ::, my_type, args) \
GENERATE_LEQ(prefix, my_type ::, my_type, args) \
GENERATE_NEQ(prefix, my_type ::, my_type, args)
Parameters
prefixThis is for something before each declaration like template<classname Foo>.
my_typethe type are defining operators for.

◆ GENERATE_EQUAL

#define GENERATE_EQUAL ( prefix,
qualification,
my_type,
args... )
Value:
GENERATE_ONE_CMP(prefix, qualification, ==, my_type, args)

◆ GENERATE_LEQ

#define GENERATE_LEQ ( prefix,
qualification,
my_type,
args... )
Value:
GENERATE_ONE_CMP(prefix, qualification, <, my_type, args)

◆ GENERATE_NEQ

#define GENERATE_NEQ ( prefix,
qualification,
my_type,
args... )
Value:
GENERATE_ONE_CMP(prefix, qualification, !=, my_type, args)

◆ GENERATE_ONE_CMP

#define GENERATE_ONE_CMP ( PRE,
QUAL,
COMPARATOR,
MY_TYPE,
... )
Value:
PRE bool QUAL operator COMPARATOR(const MY_TYPE & other) const { \
__VA_OPT__(const MY_TYPE * me = this;) \
auto fields1 = std::tie( __VA_ARGS__ ); \
__VA_OPT__(me = &other;) \
auto fields2 = std::tie( __VA_ARGS__ ); \
return fields1 COMPARATOR fields2; \
}