Skip to content

Commit

Permalink
fixup! refactor: cleanup SemanticVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Oct 9, 2024
1 parent 77798f1 commit 0f69157
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/util/semanticversion.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <compare>
#include <tuple>

class QString;

Expand All @@ -26,6 +27,9 @@ class SemanticVersion {
friend constexpr std::strong_ordering operator<=>(
const SemanticVersion&, const SemanticVersion&) noexcept;

friend constexpr bool operator==(
const SemanticVersion&, const SemanticVersion&) noexcept;

// Do not change the order because the synthesized comparison operators
// depend on it!
unsigned int majorVersion;
Expand All @@ -36,9 +40,21 @@ class SemanticVersion {
// you should not be able to create an invalid version easily from the outside
constexpr SemanticVersion()
: SemanticVersion(0, 0, 0){};
// make tuple, which is used for the implementation of the comparison operators
constexpr std::tuple<unsigned int, unsigned int, unsigned int> makeTuple() const {
return std::tie(majorVersion, minorVersion, patchVersion);
}
};

// TODO: replace with = default (synthesized) implementations once widely
// supported on target compilers.
constexpr std::strong_ordering operator<=>(
const SemanticVersion&, const SemanticVersion&) noexcept = default;

const SemanticVersion& lhs, const SemanticVersion& rhs) noexcept {
return lhs.makeTuple() <=> rhs.makeTuple();

Check failure on line 53 in src/util/semanticversion.h

View workflow job for this annotation

GitHub Actions / macOS 12 x64

invalid operands to binary expression ('std::tuple<unsigned int, unsigned int, unsigned int>' and 'std::tuple<unsigned int, unsigned int, unsigned int>')

Check failure on line 53 in src/util/semanticversion.h

View workflow job for this annotation

GitHub Actions / macOS 12 arm64

invalid operands to binary expression ('std::tuple<unsigned int, unsigned int, unsigned int>' and 'std::tuple<unsigned int, unsigned int, unsigned int>')
}

constexpr bool operator==(
const SemanticVersion& lhs, const SemanticVersion& rhs) noexcept {
return lhs.makeTuple() == rhs.makeTuple();
}
} // namespace mixxx

0 comments on commit 0f69157

Please sign in to comment.