From 42bbdd0e7f0d78b622697bf4d4543c1aead22ae8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 30 Sep 2015 17:09:45 +0200 Subject: Improve version comparison operators --- bpkg/package | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'bpkg/package') diff --git a/bpkg/package b/bpkg/package index a75d18e..9b616f6 100644 --- a/bpkg/package +++ b/bpkg/package @@ -327,9 +327,13 @@ namespace bpkg // Version comparison operators. // + // They allow comparing a lhs object that has epoch, canonical_upstream, + // and revision data members to the rhs version object. The idea is that + // this works for both query members of types version and canonical_version + // as well as for comparing canonical_version to version. + // // @@ Still not sure if this is conceptually the right way to do - // it (should we document it as an advanced technique?). Also - // the return type (query_base) ugliness. + // it (should we document it as an advanced technique?). // template inline auto @@ -342,6 +346,18 @@ namespace bpkg template inline auto + operator< (const T& x, const version& y) -> decltype (x.epoch < 0) + { + return x.epoch < y.epoch () || + (x.epoch == y.epoch () && + x.canonical_upstream < y.canonical_upstream ()) || + (x.epoch == y.epoch () && + x.canonical_upstream == y.canonical_upstream () && + x.revision < y.revision ()); + } + + template + inline auto operator> (const T& x, const version& y) -> decltype (x.epoch > 0) { return x.epoch > y.epoch () || -- cgit v1.1