libzypp 17.31.23
Comparison using relational operator zypp::Rel.

Functions

template<class Tp , class TCompare >
bool zypp::compareByRel (Rel op, const Tp &lhs, const Tp &rhs, TCompare compare)
 Comparison of two elements using relational operator op.
 

Detailed Description

Take a class like zypp::Edition. Editions are comaprable. You can compare them lexicographical, or according to their version and release values, or match them (i.e. taking empty version or release values as wildcard).

No matter which way is appropriate within a certain context. You need functions to compare, and may want to use classes like zypp::Range, based on the desired comparison.

All the class has to do, is providing a general comparison method (preferably static)

// Compare two elements returning -1, 0, 1
// if the elemants compare <,==,>.
static int compare( const Tp & lhs, const Tp & rhs );

Compare<Tp> provides a functor wrapping compare. In case the general comparison method is named differently, the class, or you, have to provide an approriate functor.

compareByRel then compares two elements using a certain operator and general comparison method.

compareByRel( Rel::EQ, lhs, rhs ); // defaults to Compare<Edition>
// thus Edition::compare
static int match(const Edition &lhs, const Edition &rhs)
Definition: Edition.h:130
static int compare(const Edition &lhs, const Edition &rhs)
Definition: IdStringType.h:127
bool compareByRel(Rel op, const Tp &lhs, const Tp &rhs, TCompare compare)
Comparison of two elements using relational operator op.
Definition: RelCompare.h:108
static const Rel EQ
Definition: Rel.h:50

Furthermore a bunch of functors using a certain operator is defined. All templated by type and general comparison method (defaults to Compare<Tp>).

// Editions sets use lexicographical order per default:
std::set<Edition>
// An Edition set using Edition::compare as order:
std::set<Edition,CompareByLT<Edition> >;
// Edition::match is not transitive, thus not an appropriate
// order relation for std::set or std::map.

Classes like zypp:Range are templated by by type and general comparison method as well. Thus you may use Edition ranges based on Edition::Compare, as well as ranges based on Edition::Match (Edition provides these two functors).

Again: Everything a class has to provide is the general comparison method. Comparison functors and ranges are then immediately available.

Function Documentation

◆ compareByRel()

template<class Tp , class TCompare >
bool zypp::compareByRel ( Rel  op,
const Tp &  lhs,
const Tp &  rhs,
TCompare  compare 
)
inline

Comparison of two elements using relational operator op.

Expects TCompare to be a binary operator returning -1, 0, 1 if the elements compare <,==,>.

// Signature of compare function or functor:
int compare( const Tp & lhs, const Tp & rhs );
  • If op is Rel::ANY, the expression is always true.
  • If op is Rel::NONE, the expression is always false.
  • Otherwise the expression is evaluated using compare.

Definition at line 108 of file RelCompare.h.