Open gotmax23 opened 10 months ago
Thank you for the suggestion. SWIG automatically generates it if corresponding operators are available in C++. Right now only 3 operators are defined. The operator bool operator<
should be implemented differently to provide requested functionality. It should compare name according to string, arch, and then EVR according to libsolv evr comparison.
class Package {
public:
// @replaces libdnf:libdnf/hy-package.h:function:dnf_package_get_identical(DnfPackage * pkg)
bool operator==(const Package & other) const noexcept;
bool operator!=(const Package & other) const noexcept;
bool operator<(const Package & other) const noexcept { return id < other.id; }
Additional information: https://github.com/swig/swig/blob/master/Lib/python/pyopers.swg
The libdnf C++ API provides a
dnf_package_cmp
function and the Pythonhawkey.Package
binding in turn exposed rich comparison methods (__lt__
,__gt__
,__le__
, and__ge__
). I used this in Python withsorted()
to print package query results in a consistent order. Would it be possible to implement the same thing in libdnf5's C++ API and Python bindings? I implemented this myself in fedrq1, but it'd be nice to have this in libdnf5 itself.