aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-30 17:09:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-30 17:09:45 +0200
commit42bbdd0e7f0d78b622697bf4d4543c1aead22ae8 (patch)
tree165c912489f845b790cc1c6b79bdb3bc12908382
parentcbcf98064cf2dd8a2da80932af799789dc2ca2a9 (diff)
Improve version comparison operators
-rw-r--r--bpkg/package20
1 files changed, 18 insertions, 2 deletions
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 <typename T>
inline auto
@@ -342,6 +346,18 @@ namespace bpkg
template <typename T>
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 <typename T>
+ inline auto
operator> (const T& x, const version& y) -> decltype (x.epoch > 0)
{
return x.epoch > y.epoch () ||